Basic ServerRpc Issue

Hey,
I’m using Unity-2022-3-LTS.10f1 and Netcode-for-GameObjects 1.6

All I’m trying to do is make a client call a ServerRpc that makes the server(in this case the host) Debug.Log its name (the host’s player name) but it when i call this on the client it the server Debug.Logs the clients name.

before anyone asks yes, this script is on a NetworkBehavior object
why?

Code:

//this is in an update loop
if (Input.GetKeyDown(KeyCode.P))
{
    TempServerRpc();
}

[ServerRpc]
public void TempServerRpc()
{
    Debug.Log("server");
    Debug.Log(transform.name);
}

1 Answer

1

Figured it out myself, I didn’t understand what ServerRPC does. So for anyone else this is what ServerRPC does:

  • if client object calls a ServerRpc, it will be executed on host’s (if you are using a client server architectures) version of said client object.