In Ulink usually there an extra parameter in the RPC method to tell who is calling RPC, i.e uLobby.LobbyMessageInfo info.
How does it work in the new unity network.
and how to declare the Command on the Server side
A command is called from a player object. It is run on the server, on that same player object. Whichever player owns that object is the player making the call.
Thanks for the reply.
My question is how the SERVER will know which client did invoke the command?
On the server, each connected client will have a player object (if this is not the case for you then then I don’t know enough about the new networking to answer your question) usually spawned from a prefab. If you have 5 connected clients you should have 5 instances of player objects.
A client can only call a command via its own player object. On the server, the command is executed on the instance of the player object that is assigned to the player that called it.
The link between the client connection and the GameObject that is assigned to it is set when the client connects and the server creates a player object for it. The default behaviour for setting this up can be overridden if you need.
Essentially, unity has some stuff under the hood to make sure your command is executed on the correct player object instance on the server.
Hope that makes sense.
Thanks for the reply.
In the Legacy unity network every RPC you can also access an extra internal parameter called NetworkMessageInfo
Will this work on the new one too?
In your method code for the Command or a ClientRPC you will have the information that is similar to a NetworkMessageInfo: this.netId is the identifier for the NetworkIdentity (similar to the old NetworkView) and this.playerControllerId is the id for the player. There are methods in ClientScene and NetworkServer to look those up by id.