I asked a question earlier in another post about additive loading of scenes. I have that all working. Players can spawn in, run between scenes, etc. etc. All good. Now I was wondering if there is a way, along with that, to have instanced scenes. That is, when going through a portal to another scene a player gets its own instance of that scene, where if another player tries to follow them, they also get only an instance of that same scene, and don't see each other/interact with the same instances of things in their respective scenes, and when they leave they go back out to one of the "shared" additive scenes with all the other players? Imagine running into an instanced dungeon in an MMO, or an owner-only hideout in GTAO.
#Another scene management question
17 messages · Page 1 of 1 (latest)
You have multiple solutions for that.
One Make instances on server not in same position, but different positions and use interest manager to send data to users depending on their position on server. So you can have a lot of stuff. This is simple to understand, not so much friendly for performance. But friendly if you need to have different actions happening at different instances.
If your scene doesnt interactions, you can spawn everyone into same spot, just update interest manager with it to shop only people in stame instance indicator. then server will have same spot but mmultiple people there.
Last one is just create new instance of server and reconect person there, when he leaves close that instance.
Yes this is doable. In the Additive Levels example there is a portal to move players to another scene. That could easily be extended to load another scene instance on server and move the player to that instead. The exit portal in that instance would unload the instance after sending the player to any other scene.
Im not sure I follow what you mean here. If I update that code to first load another scene instance of the dungeon and then move the player there, how will I tell the player which scene instance to move into. Per the unity docs, if you additively load the same scene multiple times, they will all have the same name and it's impossible to find a particular instance. (https://docs.unity3d.com/ScriptReference/SceneManagement.SceneManager.LoadScene.html)
Call this right after the yield LoadSceneAsync
Scene newScene = SceneManager.GetSceneAt(SceneManager.sceneCount - 1);
So update the portal code to in SendPlayerToNewScene do the same (or roughly the same) as AdditiveLeveltsNetworkManager.ServerLoadSubScenes but for one scene, and after he yield grab the scene handle, store it, and then send the SceneMessage?
If that's the case isn't there a race-condition where if two people try to enter different instances at the same time you could drop one of the scenes (grab the same handle on the server for both players) and leak a scene?
Unity is single threaded...the Async is somewhat fake
Good point
you only need the scene ref for moving the player to it inside that coroutine
Right in SceneManager.MoveGameObjectToScene, but I would want to hold onto that reference so that when the exit the dungeon I can unload the instance and waste server memory
I agree it's a PITA that AsyncOperation doesn't give a scene reference in the completed event
Isn't that the truth!
you don't need to hold it. When player gets to the exit, you know what scene they're in before you move them out
gameObject.scene