ClientRpc can be invoked by the server to be executed on a client.
Developers can declare a
ClientRpc by marking a method with
[ClientRpc] attribute and making sure to have
ClientRpc suffix in the method name.
Developers can invoke a
ClientRpc by making a direct function call with parameters:
Marking method with
[ClientRpc] attribute and putting
ClientRpc suffix to the method name are required, otherwise it will prompt error messages:
[ClientRpc] attribute and matching
...ClientRpc suffix in the method name are there to make it crystal clear for RPC call sites to know when they are executing an RPC, it will be replicated and executed on the client-side, without necessarily jumping into original RPC method declaration to find out if it was an RPC, if so whether it is a ServerRpc or
The following code provides an example of using
ClientRpcSendParameters, which will allow you to send a
ClientRpc to a specific Client connection(s) whereas the default Netcode for GameObjects's behavior is to broadcast to every single client.
As the host is both a client and a server, if a host invokes a Client RPC, that RPC will be executed on the host too in addition to other clients.
See examples of how these were used in Boss Room.