#How to transer player GameObjects to another Scene

1 messages · Page 1 of 1 (latest)

silent furnace
#

Hey I'm making a local mulitplayer game, I wanna add a Lobby in which the players can already spawn.
Those players are stored in a static List. When changing to the next Scene a game initator is looking through this static List and is supposed to spawn all player gameObjects in the List.
The problem is that the gameObjects are getting destroyed when loading the next Scene. Does somebody know how I could prevent this or has another take on spawning players in a new scene.
I want to spawn the same gameObject because I think I dont have to handle any things like, which controller is connected to which Player because thats handeld by the Player Input Manager.

marsh jetty
#

Have you heard of DontDestroyOnLoad and Additive Scene Loading before?

silent furnace
#

no, how would I implement it

marsh jetty
#

DontDestroyOnLoad is pretty simple, it's another scene that's always loaded in Unity, so things in that scene won't unload when any other scene unloads. you can send a gameobject to this shadow realm by doing DontDestroyOnLoad(yourGameObjectReference)

#

This works because of Additive Scene Loading. If your just using Unity's LoadScene() function, you'd be familiar with how its actually unloading the scene your currently in, then loading the scene you requested. Instead, if you provide an additional parameter like SceneManager.LoadScene(mySceneName, LoadSceneMode.Additive) Unity will load that requested scene without unloading the current one, meaning multiple scenes will be loaded at the same time

silent furnace
#

yea thats working so far

#

i now just have to rewire some refrences it takes fromt he first scene

#

I use the main camera to get always the correct up for current screen

marsh jetty
#

If your familiar with Lethal Company by chance they have the scene the ship is in loaded at all times, with the individual moon levels being additively loaded and unloaded

#

for reference

silent furnace
#

oh so DonDestroyOnLoad is using that?

marsh jetty
#

Yeah DontDestroyOnLoad uses additive loading, it's just a scene that is always loaded no matter what

#

just a little feature offered by unity

#

you can either use that scene or manage your own scene, just depends on preference

silent furnace
#

intresting