Remote Procedure Calls
Important requirements:
- They must be called from Actors.
- The Actor must be replicated.
RPC invoked from the server
Actor ownership | Not replicated | NetMulticast | Server | Client |
---|---|---|---|---|
Client-owned actor | Runs on server | Runs on server and all clients | Runs on server | Runs on actor's owning client |
Server-owned actor | Runs on server | Runs on server and all clients | Runs on server | Runs on server |
Unowned actor | Runs on server | Runs on server and all clients | Runs on server | Runs on server |
RPC invoked from a client
Actor ownership | Not replicated | NetMulticast | Server | Client |
---|---|---|---|---|
Client-owned actor | Runs on invoking client | Runs on invoking client | Runs on server | Runs on invoking client |
Owned by a different client | Runs on invoking client | Runs on invoking client | Dropped | Runs on invoking client |
Server-owned actor | Runs on invoking client | Runs on invoking client | Dropped | Runs on invoking client |
Unowned actor | Runs on invoking client | Runs on invoking client | Dropped | Runs on invoking client |
Usage example
Client:
UFUNCTION( Client )
void ClientRPCFunction();
Server:
UFUNCTION( Server )
void ServerRPCFunction();
Multicast:
UFUNCTION( NetMulticast )
void MulticastRPCFunction();
Reliability:
UFUNCTION( Client, Reliable )
Validation:
UFUNCTION( Server, WithValidation )
void SomeRPCFunction( int32 AddHealth );
bool SomeRPCFunction_Validate(int32 AddHealth);
Implement Function
Need to add a function named XXX_Implementation(). And Implement the function in .cpp.
UFUNCTION( Client )
void ClientRPCFunction();
void ClientRPCFunction_Implementation();