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, 2019 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, 2019 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\$
    – alpha_rats
    Jun 30, 2019 at 0:51
  • \$\begingroup\$ @AC Yes, there is another active scene. This coroutine just contains the scene unloading. \$\endgroup\$
    – alpha_rats
    Jun 30, 2019 at 0:54

0

You must log in to answer this question.

Browse other questions tagged .