- Home /
GameObject automatically setting itself to disabled on entering play mode
I have a GameObject which is automatically disabling itself when I enter play mode.
There is nothing, anywhere, in my code that sets the object as disabled to begin with so I shouldn't need to be setting it active. I haven't unchecked the object in the Inspector window and I've tried to force the object to be active by making a variable to store the GameObject and theVar.SetActive(true); in the Awake function, this didn't help. I've also tried this.SetActive(true);
Can anyone help me out?
Answer by TwistedDevelopments · Jul 28, 2021 at 07:52 PM
I updated Unity and it fixed whatever was wrong.
I recommend mark your answer as the accepted one so the questions will change to "answered"
Answer by d2clon · Jul 28, 2021 at 06:39 PM
It sounds to me that there is an Animation setting it as disable.
Animations run after the Update()
so this means they also run after the Awake()
(https://docs.unity3d.com/Manual/ExecutionOrder.html).. try to put theVar.SetActive(true);
in the LateUpdate()
. If it works that may be a confirmation of the Animation theory
Unfortunately I don't think it's that as I have no animations going in my project yet, none imported or used. It's strange, every time I click play the object disables itself. If I check the box for the object while I'm in play mode though, the object becomes active and operates as it should. I tried to use the SetActive as the first thing my code read after the vars declared at the top of the script. I've even tried resetting Unity and my PC but to no avail
To make sure I tested your theory and unfortunately it didn't help. Thanks anyway though
Another thing I would try is to remove the Object form the Scene and create it again (or duplicate it and remove the original) to see if there is any other Object deactivating it by reference.. also try to change the name of the object.
Answer by petur · Jul 28, 2021 at 07:40 PM
If you discarded animations and your own scripts, the only other two options I can think right now are:
Some gameobject up the hierarchy (parent or parent of the parent) could be disabled, in which case all other childs would be disabled too. In code, this state can be identified as "activeInHierarchy", as oposed to "activeSelf". Fixing this would require changing your hierarchy structure or which parts of it you disable.
Other script you have imported is disabling your gameobject. This can be difficult to track. If you don't have a lot of code you can search in all files for "SetActive(" and check if any instances found could be the problem. Another way to find the culprit would be to try to mess with how that script references/finds your gameobject to disable it. It could have direct reference, (in which case a copy pasted version of the object would not be afected), it could be by name, in which case changing the name of your go would suffice, it could be position in the hierarchy, try placing a copy somewhere else, it could be by tag, try changing the tags of your gameobject, it could be searching by a particular component, try removing all components and pressing play.
I updated Unity and it fixed whatever was wrong. I had thought along those lines and started a new project and started a fresh, it did the same so I just updated and it's fine now.
Your answer

Follow this Question
Related Questions
physics.OverlapSphere colliders 1 Answer
Does inactive Objects eat up Performance? 1 Answer
How to make a gameObject disappear when a mouse hovers and reappear when the mouse leaves? 1 Answer
Efficient Way to Create/Destroy and Switch Between Player GameObjects 1 Answer
Select Car - Multiple prefabs 1 Answer