I have a game that will have several massive levels that flow right into each other (it’s a Metroidvania game), and so I need to unload levels when the character leaves those areas, so that it doesn’t crash the game due to using too much memory.
I’ve already tried:
void OnTriggerExit2D(Collider2D coll)
{
SceneManager.UnloadScene(sceneIndex);
}
However, I read somewhere that you can’t call UnloadScene
from physics triggers for some reason. Unity - Scripting API: SceneManagement.SceneManager.UnloadScene
But they say to use UnloadSceneAsync
, which doesn’t exist. The link in the documentation is broken and my program won’t compile when I try to use it.
How to go about this? How does one unload a scene after the character leaves it?