Spawn networked player then add local object references [UNET]

Hey friends,

I’m new to the UNet Universe and am just trying to figure out how to get the NetworkManager to spawn a player and then have that networked player know about non-networked objects (GameManager, UI, etc.). I have tried creating my own NetworkManager and overwriting OnServerAddPlayer but of course, I would only be able to pass in local objects from the server there and not the local client objects which is what I’m after.

I’m sure it’s really simple but I am new to this and have been searching for an answer for a while but haven’t come across anything. Thanks in advance for your help!

Hi @DOelbaum

What I think you should do is have your own NetworkManager (A class derived from NetworkManager)
and override OnServerAddPlayer() with this:

// called when a new player is added for a client
public virtual void OnServerAddPlayer(NetworkConnection conn, short playerControllerId)
{
    var player = (GameObject)GameObject.Instantiate(playerPrefab, playerSpawnPos, Quaternion.identity); 
// Add your references.
    NetworkServer.AddPlayerForConnection(conn, player, playerControllerId);
}

More Info: Unity - Manual: Using the Network Manager