- Home /
Script disabling itself
Why is this happening? Everytime I press Play, the my GameManager script and my PlayerController script keep on turning themselves off. What is happening?
Okay, I fixed the PlayerController script from disabling itself by removing all the "instantiate" functions. Why does this do anything though?
Instantiate is just a method. It must be something you instantiated that disabled the script.
Usually an error in the Awake / Start / OnEnable can cause the behaviour to be disabled
Answer by Danielisimo51 · Apr 25, 2020 at 08:25 PM
Hi, just in case someone comes back here, this happened to me and It had to do with the void Awake. See if you have something in void Awake that can be moved to void Start and it could fix your problem. gl.
Thanks for posting this. Solved my problem in 2 secs. Wanted to add to this answer as this particular resource improved my understanding of the execution pipeline; and it might help other newbies in the same way.
Scroll down to the section: Script Lifecycle Flowchart https://docs.unity3d.com/560/Documentation/$$anonymous$$anual/ExecutionOrder.html
Answer by robnw · Jun 13, 2019 at 02:33 AM
do you have the networkmanager in the scene? i believe this disables gameobjects that have networkidentities attached to them
are only the scripts getting disabled? or the whole gameobject? try adding
void OnDisable()
{ Debug.Log("disabled"); }
to your script to see if they enable, then disable (if the message appears that means they enabled at some point). also sounds like a no brainer but double check and make sure theyre enabled while play mode is off (checked off in the inspector). you could also make sure the script isnt running any self-disabling code if its a third party script, and make sure some other scripts on the same game object arent doing it as well.
its not normal behavior so youll essentially have to troubleshoot and see why its doing that. most likely in a script.
Answer by Vivien_Lynn · Oct 05, 2020 at 01:40 PM
For me it was what @Danielisimo51 said: It had to do with the Awake function. I got a NullReferenceException in Awake. This disables my script. Two possible fixes: Use the Start function instead or fix the NullReferenceException.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
C# problem with pause menu 2 Answers
Distribute terrain in zones 3 Answers
Why don't I get 20 poits in my trigger function? 1 Answer
Changing animation duration 0 Answers