- Home /
Disable Mesh Collider Trigger
Is the OnTriggerEnter function supposed to be called when the collider that it is interacting with is disabled? Right now I have code that is being called when a mesh collider tagged as "Weapon" enters the trigger but the mesh collider is disabled. Is this a Unity bug? Is there a clean way around this other than disabling the gameobject associated with the mesh collider?
Answer by Seth-Bergman · Mar 12, 2013 at 04:43 AM
I've just tested to be sure.. if turned off, the mesh collider will not activate the trigger.. you must have another collider (or a character controller) attached to the object
OK, actually I take that back.. I was using the mesh collider on the trigger, but the other way around, yep, you're right, it still works! seems like a bug to me...
No other reason that should happen with a disabled component.. I say submit it!
as for a clean way around it.. you may want to remove/re-add the component rather than disabling it, that will be easy..:
Destroy(meshCollider);
and to add it back:
gameObject.AddComponent ("meshCollider");
Or, maybe on the trigger you can do a check like:
if(other.collider.enabled)
that should do it to..
(The second way is probably cleaner, since adding a mesh collider at runtime is more costly... And I just confirmed it DOES work)
Ok thanks a lot! I thought that was weird behavior. I will submit this later tonight.
Your answer
Follow this Question
Related Questions
Area of Damage for a Blink of an Eye 3 Answers
Why isnt OnTriggerEnter Tags working. 1 Answer
check when a projectile that is a trigger hits a mesh that is also a trigger 1 Answer
How to use different and distinguish between different box colliders? 1 Answer
Detect more than one collider trigger 2 Answers