Before updating to Windows 10 you may need to return your Pro license. More information here

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");


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(){



     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?


more ▼

asked Mar 01, 2011 at 05:05 PM

avatar image

667 354 264 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



Answers and Comments



asked: Mar 01, 2011 at 05:05 PM

Seen: 2205 times

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