- Home /
Is there a perferred method for handling scene loading?
So my question basically is this:
When loading scenes in Unity is it better to load an empty scene then load the scene you are trying to reach or is it more efficient to just have a canvas UI cover the scene and wait for the scene to load directly then hide the canvas after the loading operation is complete?
I was curious about this, whether or not using one method over the other had any pros or cons as far as your application's performance goes. Maybe there are reasons you'd want to do one over the other?
I searched online for quite some time and failed to find anything regarding this topic so I decide to post here. Maybe it would be better off in the forum, but any answers from folks who have experience with this sort of thing would be greatly appreciated.
Thank you for your time.
I suppose it would be more helpful if I provided information about what I'm doing specifically.
I am currently working on a prototype project that will act as a template for future ones. The way I am handling scene management is by having a prefab object hold my load handling script that has an array of all my scenes' information and logic for figuring out which one it needs to load as well as a UI element for displaying graphics (progress bar, optional flavor text, etc.). This gets dragged around from scene to scene and gets called when I need it to load something. I've seen before where many people were not doing it this way and had a completely separate scene (not necessarily completely empty) that they would load before loading the actual scene they were trying to reach. In fact I found out that this seems to be the norm. This caused me to wonder what actually is the best method for doing this even if the benefits are only marginal...an every ounce counts sort of thing. I also thought that having an additional loading scene seemed slightly pointless unless there was something more visually interesting and complex going on, but then I thought that maybe I'm wrong and there was a reason for doing this even in a simple application which eventually brought me here.
For the purposes of my particular project, I am not doing anything too crazy such as stea$$anonymous$$g instances of multiple scenes at the same time. I am however using asynchronous loading.
Any additional thoughts from anyone would be helpful not only to me but to anyone who finds this topic interesting and has similar questions in the future.
In terms of actual load time, not loading into a separate scene and not using asynchronous loading is the fastest. We typically use asynchronous loading for user-experience purposes. What you're doing by dragging an object around with you is basically equivalent to having a separate loading scene - however, it does mean that you're carrying that object in memory with you everywhere you go, rather than simply relegating it to a loading screen. That's about the only downside.
Thank you for all the feedback on this. I figure that what I'm doing isn't necessarily bad though maybe atypical. At least it doesn't appear to be bad for the moment. Perhaps as my project grows the memory requirement may be more of an issue, but as it exists now there isn't even a measurable difference in performance doing it one way over the other.
Thanks again, cheers!
Answer by scottishrob13 · Jul 29, 2020 at 01:43 AM
It depends a lot on what your scene management looks like. The fastest method will be to load the next scene directly SceneManager.LoadScene("YourScene", LoadSceneMode.Single)
which will unload the current scene first, so memory isn't a concern. However, this severely limits the amount of control you have. Loading an empty scene, and then the scene you're trying to get to will similarly lack control and won't be any more flexible so there's no reason for the extra step. Typically, you want to asynchronously load a lightweight loading scene (preferably with some sort of animated component so the player knows the game hasn't simply frozen up), activate it, asynchronously unload the original scene, asynchronously load in the next scene, activate it, and finally asynchronously unload the loading scene. How you hide the transitions at each step is flexible, especially since you're doing it all asynchronously and not freezing up the game. Of course, that's just for a simple case where you aren't merging scenes additively or trying to stream parts of large, open-world levels. That would require an entirely different set of approaches. As you get more complex requirements, the simple rules of thumb start to break down.