Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

how to load...

Discussion in 'Addressables' started by Icyteck01, Apr 6, 2019.

  1. Icyteck01

    Icyteck01

    Joined:
    Dec 27, 2016
    Posts:
    31
    Hello, how to load and unload scenes that changes dynamically.

    At the moment i have this :
    Code (CSharp):
    1. IEnumerator LoadScene(int mapId, bool RealyLoadMap = false)
    2.         {
    3.             MainComponent.Game.SendNotification(UINotifications.LOADING_NOTIFICATION, "Loading World: 0");
    4.  
    5.             if (RealyLoadMap)
    6.             {
    7.              
    8.                 IAsyncOperation<Scene> op = Addressables.LoadScene(scenes[mapId], LoadSceneMode.Additive);
    9.                 while (op != null && !op.IsDone)
    10.                 {                
    11.                     yield return new WaitForSeconds(0.1f);
    12.                     MainComponent.Game.SendNotification(UINotifications.LOADING_NOTIFICATION, "Loading World: " + ((int)(op.PercentComplete * 100)).ToString() + "%");
    13.                 }
    14.                 if(op != null && op.IsDone)
    15.                 {
    16.                     bool compleated = false;
    17.                     if (CurrentScene != null && StaticVars.CURRENTMAP != -1)
    18.                     {
    19.                         IAsyncOperation<Scene> opx = Addressables.UnloadScene(CurrentScene);
    20.                         while (opx != null && !opx.IsDone)
    21.                         {
    22.                             yield return new WaitForSeconds(0.1f);
    23.                             MainComponent.Game.SendNotification(UINotifications.LOADING_NOTIFICATION, "Cleaning the house: " + ((int)(opx.PercentComplete * 100)).ToString() + "%");
    24.  
    25.                         }
    26.  
    27.                         if (op != null && op.IsDone)
    28.                         {
    29.                             compleated = true;
    30.                         }
    31.                     }
    32.                     else
    33.                     {
    34.                         compleated = true;
    35.                     }
    36.                     if (compleated)
    37.                     {
    38.                         StaticVars.CURRENTMAP = mapId;
    39.                         CurrentScene = op.Result;
    40.                         SceneManager.SetActiveScene(CurrentScene);
    41.                         MainComponent.Game.SendNotification(GameNotifications.MAP_LOAD_COMPLEATE);
    42.                     }
    43.                 }
    44.             }

    but in the end its not free from Addressable memory or unity memory.

    Thanks.

    Great work btw.
     
  2. Icyteck01

    Icyteck01

    Joined:
    Dec 27, 2016
    Posts:
    31
    Also i get this warnings:
    Internal: JobTempAlloc has allocations that are more than 4 frames old - this is not allowed and likely a leak
    To Debug, enable the define: TLA_DEBUG_STACK_LEAK in ThreadsafeLinearAllocator.cpp. This will output the callstacks of the leaked allocations

    I am not using any job system... and i am using unity 2018.3.1f1
     
  3. Icyteck01

    Icyteck01

    Joined:
    Dec 27, 2016
    Posts:
    31
    nvm fixed it

    Code (CSharp):
    1.                 IAsyncOperation<Scene> op = Addressables.LoadScene(scenes[mapId], LoadSceneMode.Single);
    2.                 while (op != null && !op.IsDone)
    3.                 {                
    4.                     yield return new WaitForSeconds(0.1f);
    5.                     MainComponent.Game.SendNotification(UINotifications.LOADING_NOTIFICATION, "Loading World: " + ((int)(op.PercentComplete * 100)).ToString() + "%");
    6.                 }
    7.                 if(op != null && op.IsDone)
    8.                 {
    9.                     StaticVars.CURRENTMAP = mapId;
    10.                     MainComponent.Game.SendNotification(GameNotifications.MAP_LOAD_COMPLEATE);
    11.                 }