I'm in a situation where rather than just using Main Menu UI driven approach I have a 'hub world' where my player prefab/gameobject is already instantiated (it has NetworkObject on it, but its offline/dormant at this time, not spawned in NGO, NGO not even connected) and it walks around the hub to different spots to trigger stuff, including a Multiplayer mode place, where he can join a lobby (using Steam lobbies currently) and upon creating/joining a steam lobby I also join as a Host/Client in NGO / Network Manager (Distributed Authority, Scene Management disabled). This works ok for the initial Host/Lobby creator, but then on a 2nd Client as soon as he joins the session NetworkSpawnManager.DestroySceneObjects() is called destroying my 'offline' Player gameObject from the hub scene, which i definitely dont want to happen at this stage, as the lobby is only begining to form and its not even decided there will be a game session starting. I can't find any way of preventing this from happening, outside from just not connecting NGO Clients at this stage and only relying on the Steam lobby solution for the entirety of pre-game communication, but I would much prefer to be able to already use NGO at this point and be mostly independent of platform specific lobby solutions. Any ideas?
#Can I prevent the NetworkSpawnManager.DestroySceneObjects() call when connecting as a Client?
1 messages · Page 1 of 1 (latest)
The offline objects should not have network object components on them. Then you can manually spawn in a network object in its place when necessary. And vice versa for disconnecting.
Late joining clients will have the network objects spawn for them automatically so you would need to deal with those offline objects locally to prevent duplicates
There is also a new Single Player Transport you can use for connecting offline while still being able to use network objects. But I'm not sure how that will work with Distributed Authority.
well... its not always 'offline', it is very much the online prefab/object that i spawn and sync across all the clients during actual game session
and the NetworkObject is always on it, so that i can use the same prefab in both offline gameplay as well as online games
creating a separate prefab variant with network object slapped on it for online use isnt really a viable option, because i already have an extensive prefab variant hierarchy for my gameplay objects, so i've added a NetworkObject to the root of the entire prefab variant hierarchy, rather than duplicating each of the existing variants and doubling their total number
so NetworkObject is always there in my setup, its just dormant during offline play, or utilized during online session, and i decide when i want to Spawn/Despawn them for other clients
I would create a gitub issue on this. I'm not sure there is a way to prevent in scene network prefabs from getting destroyed and respawned on connection. Even with scene management disabled
https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/issues