- Home /
Inactive GameObject at start of scene
If I have a GameObject that its invective by default. When I start the game/scene, Does the scripts get called? Does unity load it and then set it inactive?
Answer by fafase · Dec 12, 2014 at 07:54 PM
yes it does. the awake is called regardless the state. Start is called on first run, OnEnable any time you switch on or off Some of the callbacks are waiting on the events and will be called regardless the state. Drawing and setting off is no solution since drawing is performed after all updates and if set off it won't draw.
Waiting time on start is no real issue so create them all at the beginning and put a loading screen to hide.
I'm trying to understand what is the advantage of setting it inactive in the editor. Let's say that I want to publish my scene with half of the 3D models active. Will it take the same time to load the scene if they all where active?
Load time is not as important as framerate. Performance (framerate) is hurt by what is active and unaffected by what's hidden. You keep asking about load time which is when objects are initialized and only happens once each scene. Open Unity, load in about a thousand objects, parent them to something, and test the load and run times with it hidden and viable. just testing it yourself is often the most accurate answere.
I know that it happens once, that's exactly why I'm asking this. Let me try to explain better, if I have a scene with a 100 heavy 3D models that are set to inactive in the editor. When I open/run my scene does Unity loads them even if they are inactive? Or Unity ignores them until I set them to active with a script?
I just tested it with some massive meshes. With them visible it took 3.2 seconds to load. With them hidden 2 seconds. With them deleted it loaded in 1.1 seconds. That's the practical answer. I don't know what Unity does behind the scenes.
Answer by NicRule · Dec 12, 2014 at 04:47 AM
If it is set inactive in the editor the scripts attached to it will not run. It will use the Awake() and Start() function only the first time it is activated, regardless of when this happens. If it is set inactive by its own script, it will run only to that point.
So, if I have like 100 GameObjects (its just an example) full of heavy 3D models but they all are inactive my scene should run/open fast because they are not active?
I just tested it and it takes about the same time to load even if the objects are turned off. It will take slightly less time but it still has to process a lot of objects.
Drawing then hiding is less efficient because it has to go through the process of hiding each object.
Answer by MOTYSHIZ · Jul 01, 2016 at 06:04 AM
I have Just tested this, and it seems that the scripts are not called on an inactive object. Awake() will be called if the script is inactive, not the GameObject holding the script.
This is evident in this short example: https://unity3d.com/learn/tutorials/topics/scripting/awake-and-start
Your answer

Follow this Question
Related Questions
Asset Bundle starts loaded 0 Answers
Loading a level and getting all new gameobjects 1 Answer
How to destroy a gameobject on collision and keep it dead on reload of the scene? 1 Answer
survival shooter game restarting when player dies 2 Answers
Objects are destroyed/disfunctional after changing scene 3 Answers