- Home /
Problem loading a scene and initializing it before it is displayed
Before Update() or before the object is drawn, I want the object to be initialized by my code, and it takes say 5+ sec. In order not to freeze at a frame during this time I have tried different approaches.
I cannot initialize my object in Awake or Start, because then animation will freeze at a frame.
If I do LoadSceneAsync() and wait till its done, the scene is already active.
I tried waiting till the 90% asyncLoad.progress mark while having "asyncLoad.allowSceneActivation = false", and then set a bool to true, and detect this in the main thread. I try then to load my data split in 700 chunks to do one chunk each frame. This happens after the constructor has run and before Awake, but the Editor crashes if I try to load an object and set its parent.
new_object.transform.parent = MapGenerator.theMap.transform; //'theMap' is not null, it's set in the obj constructor.
Seems I must do my initialization before LoadSceneAsync(), and then quickly just set the relevant data in Start()... But then I need to create objects and wait to set it's parent until Start() is run... All sorts of problems...
If this is the only way, I think this is a design flaw in Unity... or is there an easy way?
I'm fine with splitting the work into chunks, just need to know when/where I can run this Initialization as long as it's done before the object is drawn, and also before the previous scene is destroyed and stops drawing... seems so bad to have to do it before the scene objects exists...
maybe hide the scene with a canvas overlay image until everything is "loaded"? You can instantiate the overlay beforehand and use DontDestroyOnLoad so it carries to the next scene.
Answer by rh_galaxy · Jan 23, 2019 at 01:07 AM
I delayed all object creation to be done in Update() during a sequence of frames. Only created the mesh before also during a sequence of frames - that was allowed... accessing the transform after the constructor at 90% progress causes the editor to crash... don't know why this must happen.
I'm missing some incremental Init() member that is run before Start() once every frame until it returns true and keep running the previous scene during this time. That would solve a lot.
Concealing the scene with a plane until it has loaded is no good... because the physics is started then and some objects start to move while others does not exist...
But maybe it is meant to be done in another way...
Your answer
![](https://koobas.hobune.stream/wayback/20220612190243im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to have multiple scenes concurrently runnning 3 Answers
Load AssetBundles and External Scenes dynamically 0 Answers
Not loading in Chrome 0 Answers