NetworkLobbyManager: How to spawn a lobbyprefab as the child of another GameObject.
I'm working on a class which inherits from the UnityEngine NetworkLobbyHandler, and I'd like to make some modifications to have the lobbyPlayer prefab spawn inside of another GameObject simply called lobby, to help me contain all of the players.
The lobby GameObject needs to either be server-only, or synced so that it stays up to date on both client and server.
The syncing is something I can manage, but whenever I try to spawn the lobbyPlayer inside of the lobby game object, this only works on the server. Furthermore, the method I am using to change the parent of the instantiated lobby player (OnLobbyServerCreateLobbyPlayer) is only called on the server, and I can't figure out where in code the lobbyPlayer is spawning on the client.
I was hoping somebody with more experience of the NetworkLobbyManager would be able to point me in the right direction here, I feel like I'm getting nowhere alone.
Here's what I have on the server, which is working as expected.
And here's the client, lobbyPlayers aren't in the _Lobby object.
Answer by A13x231 · Sep 18, 2016 at 07:03 PM
For anyone following this question, I spent a long time doing some research, and it doesn't seem that spawning the prefabs as a child is the best option. Unfortunately, this would require rewriting lots of components of the HLAPI, like the network identity, which contains the Spawn method used by clients. Some of the methods aren't just overwritable too, but if you're facing the same issue and you would like to attempt this approach, the source code for the HLAPI is here
In my scenario, I have a PlayerData script attached to the prefab. I simply spawn the prefab normal and changed the parent when the PlayerData script start method is called.
I was concerned that this method would create a small gap in which the transform had not yet been updated, but I've not experienced any issues when gathering gameobjects in the lobby transform so apparently not.
Your answer
Follow this Question
Related Questions
Setting parent on spawned object Unet 0 Answers
Delay the spawning of networked player objects. Why is this so difficult with UNet..... 1 Answer
Unet - similar spawn functions acting different, client scale not transferring 1 Answer
Unet - spawning bullets, two issues 1 Answer
How do I use an InputField to change a player object's variable? 1 Answer