Hello, how to load and unload scenes that changes dynamically.
At the moment i have this :
IEnumerator LoadScene(int mapId, bool RealyLoadMap = false)
{
MainComponent.Game.SendNotification(UINotifications.LOADING_NOTIFICATION, "Loading World: 0");
if (RealyLoadMap)
{
IAsyncOperation<Scene> op = Addressables.LoadScene(scenes[mapId], LoadSceneMode.Additive);
while (op != null && !op.IsDone)
{
yield return new WaitForSeconds(0.1f);
MainComponent.Game.SendNotification(UINotifications.LOADING_NOTIFICATION, "Loading World: " + ((int)(op.PercentComplete * 100)).ToString() + "%");
}
if(op != null && op.IsDone)
{
bool compleated = false;
if (CurrentScene != null && StaticVars.CURRENTMAP != -1)
{
IAsyncOperation<Scene> opx = Addressables.UnloadScene(CurrentScene);
while (opx != null && !opx.IsDone)
{
yield return new WaitForSeconds(0.1f);
MainComponent.Game.SendNotification(UINotifications.LOADING_NOTIFICATION, "Cleaning the house: " + ((int)(opx.PercentComplete * 100)).ToString() + "%");
}
if (op != null && op.IsDone)
{
compleated = true;
}
}
else
{
compleated = true;
}
if (compleated)
{
StaticVars.CURRENTMAP = mapId;
CurrentScene = op.Result;
SceneManager.SetActiveScene(CurrentScene);
MainComponent.Game.SendNotification(GameNotifications.MAP_LOAD_COMPLEATE);
}
}
}
but in the end its not free from Addressable memory or unity memory.
Thanks.
Great work btw.