So I’ve read many threads on this topic, but most are dated and contain somewhat conflicting information for what, I think, must be a common issue, so I’d really appreciate it if anybody could share what they believe to be best practice with Unity 5.5 in 2017:
I have a “hub” level, with portals leading to many different levels in the game. The hub itself is a scene, as are each of the levels in the game that it leads to. The levels are quite large and so, in order to reduce loading time, I use LoadSceneAsync with allowSceneActivation set to false to begin loading the level assets as the player approaches the corresponding exit from the hub (as they run down the corridor that leads to the level 5 world, start loading level 5, for example). Then, when they actually enter the portal for that level, flip allowSceneActivation of the async operation to true to load the last part of the scene. Makes sense, right? And, for the most part, works great and produces a nice experience for the player.
The problem comes when the player starts to approach the level 5 portal (so LoadLevelAsync has begun), but then changes their mind and decides to go to Level 4 instead. The partially-loaded level seems to get stuck - unable to be unloaded by UnloadSceneAsync, but unable to have its resources freed any other way. So I have to activate it and then immediately destroy it to be able to start loading the correct level instead. Is it just me?
What I’d probably do… lock them into going to level 5 when they head towards that one. Basically there’s a point of no return in the corridor, and at that point is when you start loading async.
Hi! Thanks for the reply. Unfortunately, that solution is not really acceptable. My fault - I know I gave the example of “running down a corridor”, but in practice our hub world is much more open than that. I don’t want the player to get locked in to visiting a level just because they wandered past the portal leading to it on their way to somewhere else.
Note I was giving a work around for what is clearly a flaw in the system.
Otherwise… you’re going to have to wait for a fix? Maybe a issue a bug/feature request asking for the ability to cancel an async load. But since it appears to be something discussed a lot for years, it’s probably low on the list.
Another option would be to load the level additively, delete the hub level after load… and if they cancel, delete the loaded level that you don’t want when it completes.
Additive Load is a good idea - I think I will try parenting all the objects in my level scenes to a single, disabled, GameObject. Then, as the player approaches the portal, use Additive LoadSceneAsync with allowSceneActivation true to let the level load fully (but completely disabled). Then, as the player enters the portal, enable the newly-loaded scene gameobject and delete the hub scene. If they move away from the portal, however, delete the level scene. It should be a similar result to what I was trying to achieve before. Cheers for the suggestion!