Why does disabling collision script cause issues?

I tried to do the collision cheatkey by disabling my collision script in my rocket, with something like

GetComponent<CollisionHandler>.enabled = false;

I imagined the rocket will just do nothing when colliding. But for some reason, the rocket still processes the crash sequence. Particle and sounds still play, though now with bugs. What is the issue here?

I would recommend sending a screenshot of more of your code so that when the TAs and problem solvers roll around they can better assist you, or maybe I can assist you.

Disabling a script only prevents things like Update() from running. From the documentation here

If you are not going to be enabling behaviours (as stated above), you can first check if the behaviour is enabled before processing the collision

void OnCollisionEnter(Collision collision)
{
    if (!enabled) return;
    // do the things
}
1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms