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!

1 Answer

1

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 confirming. Must say not something I'd noticed before, but very useful! Thanks