0
\$\begingroup\$

I am using the following coroutine to attempt to unload asynchronously a loaded but inactive scene in Unity :

private IEnumerator sceneUnloader(string s)
{

    AsyncOperation asyncUnload = SceneManager.UnloadSceneAsync(s);

     while (!asyncUnload.isDone)
     {
        Debug.Log("[SCENE UNLOAD] " + asyncUnload.progress);
        yield return null;
     }
    }
  • The scene name input is valid, as it's the same variable used to preload the same earlier, and the scene is being preloaded correctly.
  • There is an active scene when this coroutine is being called, as the attempt is to unload a partially preloaded scene while another one is still active.

The AsyncOperation is apparently null, is there a way to get around this issue and unload from memory an inactive scene?

I'm currently hacking around this issue by waiting for the scene to be fully loaded and activated, and then unloading it.

\$\endgroup\$
4
  • \$\begingroup\$ If UnloadSceneAsync is returning null, are you sure you've passed it a valid input? \$\endgroup\$ – DMGregory Jun 28 '19 at 14:10
  • \$\begingroup\$ Do you have another active scene? Also, what's the prototype for the function this code is in? \$\endgroup\$ – A C Jun 29 '19 at 2:51
  • \$\begingroup\$ @DMGregory yes, the input is correct, if I call the unloading with the same input after completion the scene being loaded and activated, it works fine \$\endgroup\$ – a_rrats Jun 30 '19 at 0:51
  • \$\begingroup\$ @AC Yes, there is another active scene. This coroutine just contains the scene unloading. \$\endgroup\$ – a_rrats Jun 30 '19 at 0:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.