i have a problem with a script that disables itself for no reason. The script works fine on another Prefab.
If i attach it to a Gameobject it is disabled the moment i hit play. What am i doing wrong?
The script contains references to animations, other gameobjects as well as strings and ints. Not all references point to existing objects. But as long as the script compiles and runs there should be no reason to disable itself. I hope i am missing something that is easy to fix.
When i commented it out it worked. The purpose of putting them in layer 2 was to make it always appear on top of everything. Nothing else is in layer 2. But i don´t know why it deactivated the script. So i probably am not fully aware of the layer concept. If someone knows why this happened please let me know.
i had an object already placed on the field
then when i use awake it starts the script disabled ,
so i remove awake and just use void start and it works fine
For the archives: Unity will disable a script if it throws an exception in Awake().
So, if you find a script mysteriously disabled when you run your game, find and fix whatever errors itâs tripping over in its Awake method, and the problem will go away.
Yes, those error does not show in Unity Editor Console for me. Iâve added Assert in Awake and Start method in my MonoBehaviour so I can see the stack trace in Console window this way.
SOLVED i didnt check my console for errors and there were no compile errors so i didnt know what was going on, coming here i found @coronepan 's comment and i replaced my awake method with a start, it worked but i wanted to use the awake method and didnt know why the start method worked and awake didnt, then i saw @JoeStrout 's comment and looked in the console after running it again, i hadnt manually put in a null reference exception so i wasnt expecting anything, but upon further investigation into the report i saw it trying to say i have a null reference exception at line 29, looking in the script i found where i tried incorrectly assigning the post process volume component âcamcheck = GameObject.Find(âcamcheckâ).transform;â (unity 2020.3) and by commenting/deleting it out, voila
thanks guys.
Just some info for anybody else with this problem that hasnât been able to fix it. Try this video. It might just be a script execution order issue that can be fixed in the settings.
I had this issue in one of my scenes, that I had made when I was A LOT more green behind the ears.
And basically⌠I just was not using the objectâs proper name, when using GameObject.Find. The examples/tutorials that I was following all had objects that had the exact same name as the script we were looking for, whereas in my scene, the game objects had descriptive names, but not exactly the same as the script on the objects!
I was also âfindingâ them in Awake, which caused Unity to deactivate the script when I hit play.
I guess it works when you wake up, as its name suggests. Because I had such a problem, too, and based on what you explained, I set the malfunctioning objects to be disabled when the game started and enabled them when the game started. It started working properly.