[ServerRpc(RequireOwnership = false)]
public void SomeServerRpc()
{
// Get Client ID here
}
There is now a better way of doing this using ServerRpcParams: ServerRpc | Unity Multiplayer Networking
Check the “Best Practice” example.
public void SomeServerRpc(ServerRpcParams serverRpcParams = default)
{
var clientId = serverRpcParams.Receive.SenderClientId;
}
NetworkManager.Singleton.LocalClientId
I don’t think that you can get the client Id from a “context” or whatever, so simply pass it as parameter.
[ServerRpc(RequireOwnership = false)]
public void SomeServerRpc(ulong clientId)
{
}
And use it this way
public void SomeActionOnClient()
{
networkObject.SomeServerRpc(NetworkManager.Singleton.LocalClientId);
}
This is also the way the Boss Room example does it, you can download it here: Boss Room – Small scale multiplayer co-op game sample | Unity