x


why i can not destroy the collider

hello everybody!

i need some help about destroying colliders.

to speed things up i am trying to optimize some functions. i have a bunch of objects that have mesh colliders. mesh colliders work very well for precise selection but when i need to interact with a lot of objects and chech OnTriggerEnter everything slows down terribly.

i tried with boxcollider and it works very fast. when i do need precision selection i would like to turn meshcolliders back on objects to replace the boxcolliders. i tried to track what object i replaced meshcollider with boxcollider and later just loop through the array and to replace boxcollider with meshcollider

here is what i tried:

first i declared the array that will hold the colliders

var boxColliderObjects = new Array();

then in every OnTriggerEnter i have this code:

function OnTriggerEnter(col : Collider){

if(col.GetType() == MeshCollider){ boxColliderObjects.Add(col); var temp : GameObject=col.gameObject; Destroy (col); temp.AddComponent ("BoxCollider");
}

//DO STUFF ON COLLIDERS }

this way i have array that holds all colliders that we changed collider type, so that i can track them and restore them later.

here is the function that should replace box colliders with mesh colliders when i need precision selection

function RestoreMeshColliders(){

   for(i=0;i<boxColliderObjects.length;i++){

     //Debug.Log(boxColliderObjects[i].name);

     var temp : GameObject=boxColliderObjects[i].gameObject;
     Destroy (temp.collider);
     temp.gameObject.AddComponent ("MeshCollider");
   }

}

it replacing mesh with box collider works, but returning back from box to mesh collider does not... any ideas?

thanks!

more ▼

asked Mar 01, 2011 at 05:05 PM

pretender gravatar image

pretender
632 354 263 271

(comments are locked)
10|3000 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3027
x614
x251
x76

asked: Mar 01, 2011 at 05:05 PM

Seen: 2125 times

Last Updated: Mar 01, 2011 at 05:05 PM