跳至主要内容

Remote Procedure Calls

Important requirements:

  • They must be called from Actors.
  • The Actor must be replicated.

RPC invoked from the server

Actor ownershipNot replicatedNetMulticastServerClient
Client-owned actorRuns on serverRuns on server and all clientsRuns on serverRuns on actor's owning client
Server-owned actorRuns on serverRuns on server and all clientsRuns on serverRuns on server
Unowned actorRuns on serverRuns on server and all clientsRuns on serverRuns on server

RPC invoked from a client

Actor ownershipNot replicatedNetMulticastServerClient
Client-owned actorRuns on invoking clientRuns on invoking clientRuns on serverRuns on invoking client
Owned by a different clientRuns on invoking clientRuns on invoking clientDroppedRuns on invoking client
Server-owned actorRuns on invoking clientRuns on invoking clientDroppedRuns on invoking client
Unowned actorRuns on invoking clientRuns on invoking clientDroppedRuns 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();

Reference