- Home /
Question by
AntLewis · Dec 05, 2013 at 07:45 PM ·
ontriggerenter
Component disabled, but still receiving Collision messages?
Hi there, I have a component disabled at run time (which I activate when needed). However, I'm noticing that it's still receiving OnTrigger() messages while it's disabled - is this behavior expected?
Thanks!
Comment
Best Answer
Answer by stevethorne · Dec 05, 2013 at 07:57 PM
Yes, this is how it works. What you could do is check if the script is enabled in your OnTrigger function like so:
void OnTriggerEnter( Collider collider )
{
if ( !this.enabled ) return;
// this code wont be called if the script is disabled.
}
It's not unfortunate, it's a deliberate feature and quite useful.
Ok thanks for confir$$anonymous$$g. $$anonymous$$ust say not something I'd noticed before, but very useful! Thanks