I have a method in my “LevelManager” that goes like this
public void SwitchLevel(string levelToLoad)
{
if (!NetworkManager.Singleton.IsServer) return;
NetworkManager.Singleton.SceneManager.UnloadScene(SceneManager.GetSceneByName(currentLevel));
NetworkManager.Singleton.SceneManager.LoadScene(levelToLoad, LoadSceneMode.Additive);
}
What i want is for when this method is called, that the current level, an additively loaded scene, is unloaded, then the next level is loaded additively.
I have already set the ClientSynchronizationMode to Additive.
When i call the above method the “currentLevel” scene unloads, but the next level’s scene does not load. Does anyone know why that is? How i can do what I want here?
It‘s far more complicated than that because you can only have one load operation going on at the same time.
This is my ServerSceneLoader (GPL3 license), it‘s 300 lines just to handle the server side additive load/unload procedure. It is accompanied by a ClientSceneLoader which handles client only scenes. Also note that if a client disconnects, the client is the one responsible for unloading the additively loaded scenes by the server.
hmm, i did not know you could only have one load operation going at once. Is that something that pertains to the NetworkSceneManager, because I have certainly loaded many scenes at once using loadasync in the regular unity scenemanager?
Supposing we can only perform one scene operation at a time, then couldn’t a possible solution for my case be to wait until after NetworkSceneManager.OnUnloadEventComplete to start loading the next next scene?
I already have systems in place for when a player disconnects to be brought back to a main menu and the non-relevant scenes unloaded, but I was always curious what happens if a client drops during a networked scene loading? The docs aren’t clear about it. Does NetworkSceneManager.OnUnloadEventComplete ever finish in that case or does it get “hung up”? It feels weird having to wait for all the clients to finish unloading/loading before the server can do anything.
You should read the manual section about scene loading (again). It’s all in there.
Yes the single load event is NetworkManager specific.
Probably but I prefer to hook into the AsyncOperation’s complete event since that always works and since you have that available, it’s just nicer to use that rather than having to implement another event method. That’s what I do in my code.
This is normal because you want everyone to start off on the same footing rather than one running off and picking up the best items or something.
The alternative is to allow late-joining clients.
On the server you get the complete event after a timeout, and you also get a parameter which contains the client ids that didn’t complete the loading.