- Home /
What is the best way to detect level load on additive/asnyc level loads
I basically want to duplicate the functionality of OnLevelWasLoaded(int level) but for these functions: Application.LoadLevelAsync
Well OnLevelWasLoaded gets called when a new scene is loaded. However, it doesn't work when you load a level asynchronously or additively. I want to be able to know when a scene is loaded regardless of whether it's done regularly, ascynchronously, or additively.
I have taken a glipse at GetStreamProgressForLevel, but I'd rather not have something constantly running in Update. And if I do, then how can I use it correctly.
Answer by iwaldrop · Jul 01, 2013 at 09:39 PM
In cases like this I use a LevelLoader which has events that get called. You declare your own events and then call them before and after the load event.
public delegate void LevelWillBeLoaded();
public delegate void LevelWasLoaded();
public static event LevelWillBeLoaded OnLevelWillBeLoaded;
public static event LevelWasLoaded OnLevelWasLoaded;
public void LoadLevel(string levelToLoad)
{
StartCoroutine(LoadLevelCoroutine(levelToLoad));
}
IEnumerator LoadLevelCoroutine(string levelToLoad)
{
if (OnLevelWillBeLoaded != null)
OnLevelWillBeLoaded();
yield Application.LoadLevelAsync(levelToLoad);
if (OnLevelWasLoaded != null)
OnLevelWasLoaded();
}
awesome! I was wondering if there was a solution if I didn't control when the application called LoadLevelAsync/Additive. In my case a wrapper isn't really an option
There isn't anything else that I'm aware of. If you don't $$anonymous$$d me asking, why is a wrapper not an option?
i want a my code to react to any call to Application.LoadLevel in any form. I don't want the user to have to have to call another function to load a level. I want it to be generic. Right now it responds to Application.LoadLevel, but it doesn't respond to LoadLevelAsync. I guess using GetStreamProgressForLevel is unavoidable?
Ahh, ok. Figured it was an in-house project. For a tool then, yeah, as far as I know that would be your best bet.