UNET: NetworkServer.Spawn

I’m having a problem with my game and need to understand the Spawn method a little better. Hoping someone can help me achieve this.

Why does NetworkServer.Spawn not create a duplicate on the server.

From what I see most examples do the following

[Command]
public void CmdSpawnSomething()
{
   var objectToSpawn = Instantiate(prefab);
  
   //set up objectToSpawn

   NetworkServer.Spawn(objectToSpawn);
}

from what I understand is this will run on the server (command) and create an instance on all clients.

My question is - why does this not create a duplicate ‘objectToSpawn’ on the server?

Why should it? I don’t think such functionality would make too much sense. Object instantiation and spawning over network seems to be uncoupled by design for good reason.

Note that you can have a look at the NetworkServer source if you want to retrace exactly how it works.

Thanks for the clarification.

The problem I’m having is that a duplicate is being created. It doesn’t happen with any other objects where I’m using the same pattern but I’ve always had a nagging doubt because this code reads like it will create a duplicate (even though that wouldn’t make sense)

Thanks for the reminder that the source is on bitbucket. Very useful.

Okay, now you got me confused. :eyes:
What is the actual problem?

So sorry - missed the notification on this post and feel very rude.

My issue was nothing to do with NetworkServer.Spawn. I was actually instantiating the object again on the client in rare circumstances that was hard to debug. Found myself drawn into the red herring that NeworkServer.Spawn might create another instance.

Since we are on the NetworkServer.Spawn topic…
Say I unspawn a player on defeat via NetworkServer.Unspawn and disable colliders, renderers and stuff on the server.
For the next round I want to respawn all defeated players via NetworkServer.Spawn (after enabling disabled stuff).
The problem is that no client has control over his player object.
Does anybody know how to make sure that every player-client gets his player object spawned that he can control?
Oh, and I have nothing checked on the Network Identity, if that matters…

Wouldn’t you use NetworkServer.SpawnWithClientAuthority ?

Yea that might work…
But silly question: how do I get the right player or connection for that fnction?