I am loading scenes async using addressables like so

    AsyncOperationHandle<SceneInstance> asyncOperation = Addressables.LoadSceneAsync(sceneReference, LoadSceneMode.Additive);
            while (!asyncOperation.IsDone)
                if (asyncOperation.PercentComplete < 0.9f)
                    Debug.Log($"\t{sceneReference.Name} Loading progress: {asyncOperation.PercentComplete * 100}% frame:{Time.frameCount}");
                    Debug.Log($"\t{sceneReference.Name} Loading complete but still in loop?: {asyncOperation.PercentComplete * 100}% frame:{Time.frameCount}");
                yield return null;

It reaches 90% on the first frame, which, based on my reading should mean it's finished loading.

However, the console spits this out: enter image description here

So it's not actually finishing the load until 3 frames later.

I'm at a loss to figure this out. Shouldn't it exit without a single iteration through the while loop? My game shows a very brief flash when swapping between screens, as I've already unloaded the previous scene and there is this 3 frame gap before the new scene appears.

Any help would be much appreciated.

  • \$\begingroup\$ Why are you unloading the previous scene before the async operation reports that it's done? The whole point of doing this asynchronously is usually so that you can keep playing in the old scene or showing a transition state while the next scene is readied. \$\endgroup\$
    – DMGregory
    Feb 28, 2023 at 16:03
  • \$\begingroup\$ @DMGregory We didn’t go that route initially because we are targeting very low end devices, and didn’t want multiple scenes open at once. I suppose we should have tested it though before making the assumption this would be a problem. We currently have business requirements to not have a transition screen during this particular load. Any idea why it’s getting stuck for a few frames? I’m curious to understand this problem, even if it turns out it’s fine to do the unload after. \$\endgroup\$ Feb 28, 2023 at 16:30
  • 1
    \$\begingroup\$ I don't think it's "getting stuck", I think the progress percentage is just not linear (the docs do not guarantee that it must be). There's some amount of work at the end of the load, like deserializing or wiring up references, that's difficult to accurately predict and divide into neat percentage figures. The engine isn't just sitting twiddling its thumbs for two frames for no reason. \$\endgroup\$
    – DMGregory
    Feb 28, 2023 at 16:33
  • \$\begingroup\$ Have you considered using allowSceneActivation to stop the new scene from rendering until the load has completed and you've unloaded the previous scene, to avoid having two running simultaneously, while still not allowing a gap in between? \$\endgroup\$
    – DMGregory
    Feb 28, 2023 at 16:34
  • \$\begingroup\$ No I haven't but this approach makes sense. Definitely will try it out and update you later on. What's the best way to reach out to you? I'm worried the comment section will become very bloated. I guess just make a new post on this question and tag you? @DMGregory \$\endgroup\$ Feb 28, 2023 at 16:45


You must log in to answer this question.

Browse other questions tagged .