- Home /
What is happening while loading the scene?
So, I do not clearly understand what processes are performed while loading a scene. I load my main scene from menu , using loading screen, so the scene is showed after complete loading , but what is complete loading? Does it include awake method of objects? I'm asking , because I have method , that load the data from file , and then some objects get information from that loading data in Awake method. And I don't understand whether this loading of data is heppening after loading the scene or while loading the scene. Perhaps a little confused explanation, sorry for that.
Answer by rh_galaxy · Apr 04 at 11:40 AM
I think it all happens on the first frame after a scene load. Something I think is called scene activation is done after 90% has completed while doing LoadSceneAsync(). If you use LoadScene() it happens after that.
//this is run on the first frame after scene change
Awake(); //on all game objects
Start(); //then this
Update(); //then this
To avoid frame rate hickups I spread out heavy initialization work during the first frames in Update(), but it's often impossible to have fully smooth transition between scenes, because Async works poorly.
For an example of LoadSceneAsync you can look at my answer to this. https://answers.unity.com/questions/1887185/loadsceneasync-never-completes-if-allowsceneactiva.html
But there are many other questions about this.
Yes, I use LoadSceneAsync, but don't understand what exactly this method do. Loading data from file is happening while loading the scene or these are 2 different action , performed apart of each other?
I think you can divide it in this sequence for LoadSceneAsync().
Multithreaded loading of new scene 0..90%
(Here you have the chance to run own initialization code, like generating a mesh for your scene, you can use threads but some calls must be made from the main Unity thread or it will crash)
Scene activation of new scene 90..100%
Scene unload of old scene
Awake(), Start(), first Update()
Not sure where 4 takes place though.
Your answer
