Determine which client a [Command] is coming from?

Is there any easy way to tell from server side which client a command came from? Basically I’m making a game wherein objects are moved around, I only want player A to be able to move around player A’s objects.

I’m currently using NetworkServer.SpawnWithClientAuthority(GameObject obj, GameObject playerObj) but this doesn’t seem to make a difference.

It may also be important to note that I am not moving objects around via a network transform.

So, a command is just a function, and because we designate them as attributes we can have any function signature we’d like on a command.

When you spawn your player, assign an Id to that player using a guid or integer, but make sure it’s unique. Guid.NewGuid() is easy to get a unique value.

Then, when your client side script invokes the command, have one of the parameters of the command be the unique id of the player. You can store it in a local variable, or even spawn an object on the player that’ll hold it so you can use GetComponent.

It MAY be possible, and someone might know better than I, using uNet - how you would get something unique off the players NetworkIdentity - I know it has that ability, thats the entire reason it’s there…I’m just not familiar how to use it.

NetworkIdentity.netId should do what you want. Every networked object will have a NetworkIdentity component, and their netId value should be synced from the server which will make every object have it’s own unique ID.

You can then use NetworkServer.FindLocalObject() to search for the object with that netId.