What actually happens when loading a scene?

Similarly to questions about the order of calls to Awake(), Start(), FixedUpdate(), Update(), LateUpdate()… What’s the order of the things* that happen when loading a scene (for example when calling Application.LoadLevel(1)? I couldn’t find any information on the topic.

When are assets loaded? When are GameObject instantiated? When are prefabs instantiated? And so on.

  • I would love to be more explicit than that, but as I said I couldn’t find anything on the precise steps that take place.

As much as it would be nice to have a definite answer for this, I certainly hope (and suspect) that Unity does not state an official answer. The reason is: this is almost always subject to change and optimize in all future versions and stating any relationship makes it harder to change later.

Especially in initialization, there is soooo much performance you can gain if you are able to play around with the orders. That is not only true for “future versions”, but also for different platforms or when detecting the presence of different hardware or OS settings. (For example, it might be totally different when loading from an SSD harddrive where random access in parallel to several dozen files are totally OK compared to a DVD where you really only want to stream one single big blob and load everything sequentially before even starting to allow the user scripts to do any other I/O code…)

So every statement, every guarantee, every documentation from Unity would diminish their ability to optimize this in the future.

So basically, the best answer to this is: Try to depend as few as possible on initialization order, especially when it comes to order of loading and initializing assets. (This is especially true for OnAfterDeserialize)

When you really need some order for your own code, then you can always load the assets by yourself using Resource.Load.