what happens if you async.allowSceneActivation = true before the scene is loaded?

Trying to debug some rare edge cases that happens during scene transition.

Given that async scene load is completely bonker in Unity it’s been fair game to blame it for most problems and usually it was a good guess.

This seems to be such case but I wanted sanity check before I start increasing activation delay.

Scene transition is done like this:
var asyncLoading = SceneManager.LoadSceneAsync(sceneToLoad, LoadSceneMode.Single);
then 2 seconds later
asyncLoading.allowSceneActivation = true;

I don’t wait on scene load as most of the time scene load is fast enough.

Could this cause the loading to freeze up if it hasn’t completed?

Doesn’t having it true before the scene loads just mean it’ll just proceed to load that last 10% that it waits on if otherwise false?

Admittedly I use Addressables so I can just properly await the function in an async method.

May I ask you why are you doing this? What is the root cause starting your load as allowSceneActivation = false? Because 2 seconds is very short for a “loading” text and certainly doesn’t sound like if you would be waiting for a keypress to start the new scene. (I usually loaded the scenes with activation false when I wanted the user to hit a key when they are ready at the end of a longer load)

Depends on what you call “freeze-up”. You are clogging the async load/unload system for sure. Since only one async load/unload can be active at a time. So if your problem is that the other scene doesn’t unload while you’re don’t enable scene activation, the answer is yes.
And also, the scene won’t be enabled until you set this to true, obviously, so in a way you’re freezing it up.
But obviously if you can elaborate what is your symptoms under the term “freeze up”, we maybe have better ideas what’s the problem. :slight_smile:

1 Like

Had tons of “fun” before we found out Unity pauses all async loading operations, including asset bundle/addressables, when it hits the magical 90% when allowSceneActivation is false.

I swear, the async loading code in Unity must be held together with spit and paper clips.

4 Likes

Well, it is this way forever (before Unity 5) and the documentation always contained how it works, so… IDK.

@ it’s waiting 2 seconds to prevent hiccup in the middle of fade 2 black. That’s where I hide load time so I don’t have to display a “loadin…” screen.

The root FSM is built to only do 1 scene load at a time but there is another path to load scene which never gets called - but never say never - so I’d like to ongui the async scene load queue.

last I checked there was no access to this queue (which is bonker) but maybe someone knows a workaround?

Note that some times loading of particular scenes take 5 seconds instead of the usual 1 second. no idea why. even with fully unloaded assets in a test project never takes more than 2 seconds.

IDK anything about your game (well, other than what you just mentioned and I vaguely remember some discussion from a couple of months ago about scene loading through the manager versus Addressables, I guess it’s still the same thing).

Waiting concrete number of seconds is generally not a good idea. Especially if you target multiple platforms eventually. But even on PC, loading times will differ. Even on the very same PC for the very same user with the very same equipment. Maybe it fits into 2 seconds when your computer doesn’t do anything else. But if you have a HDD and it gets fragmented, it takes more time to load. If you have SSD and your OS decides that it’s a great time to trim your drives, it gets more time to load. If one of your background apps decide that it’s time to wake up and load up its data: more time to load.
I would rather do the following:

  • make one helper class to load
  • load async just like before with allowSceneActivation = false
  • check out the documentation example and measure the progress
  • when it becomes 90%, activate the scene (check the example)
  • also measure time, after a second or two show some simple animation indicating loading (having a simple loading scene in memory usually feasible)