How to spawn one prefab multiple times and have unique names and tags

I have been testing this but cannot get it to work properly. What i am trying to do is:

  1. Have one prefab named “_BackSide”
  2. Instantiate in OnStartServer, tested on client as well, and then change name and tag and then spawn

The result is that it all works great at the host/client but on the remote client i spawn the prefab but it does not have the correct name and tag. It still have “_BackSide” as a name and all the prefabs have the same tag.

The following code is what i am testing now, i do not change tag in this code.

public override void OnStartServer() {

        temp_GameObject = Resources.Load ("_BackSide") as GameObject;
        temp_GameObject.name = "Zappa";
        Instantiate (temp_GameObject);
        NetworkServer.Spawn (temp_GameObject);

    }

What i am missing here?

What is the class that the function above is in? Did you subclass NetworkManager / NetworkLobbyManager or a NetworkBehaviour script?

Thanks, want to help if possible!

Arun

public class MP_GameEngine : NetworkBehaviour

You simply expect NetworkServer.Spawn to do more than it is supposed to do.
In fact, this functions spawns the original prefab on the clients on the proper position, with right network id and such. However, the spawn function does not automatically sync all object properties.

You need to manually sync those object changes you make on the server. Have a look at the official docs tree example. The numLeaves properties is made a SyncVar for a reason.

Alternatively, you could use custom spawn handlers to have higher control on object spawning behaviors.

1 Like

Thanks moco2k, i think this is my mistake. When i read this: https://docs.unity3d.com/Manual/UNetSpawning.html i realized exactly what you stated. I have not had time to implemented it yet but will start testing ASAP.