Prefab script being called even though it is unchecked

Hi all, hope you could help me understand linking scripts better. I downloaded a free character asset from the Unity Asset Store, and it comes with a character control script and Animations Controller, which are attached to the character. From this character prototype, I created an individual player in the hierarchy as well as a bunch of AI using a prefab.

I’m having trouble discerning the behavior of my the control script, which controls character movement. I unchecked this in my AI prefab because I don’t want the movement input to move the AI. So this works as intended since I can only move the player. However, I just discovered a bunch of methods from this script are being called by my prefab AI such as OnCollisionEnter(),OnCollisionExit(), which are used to trigger various animations. How could these methods be called (even though the script is unchecked in the Inspector), while others that control movement are not?

I’d remove the scripts from the ai, since they shouldn’t ever need to be enabled for any reason.

A script that is disabled (unchecked) doesn’t mean code on it can’t be run. It means certain methods that would be called at specific times won’t be called, such as Awake, Start, and Update. A lot of the rest of the script can still be called. In your specific example see bolded:

To really prevent a script from doing anything, you should remove it from the object.

1 Like

Thank you that is helpful. However, when I remove the script from the bots, it is also removed from the player.

Male two prefabs, one of ai, one of player.

1 Like