[C++] How do i set a function to be replicated over the network ?

How do i set a function to be replicated over the network ?

I had trouble with this but then I’m a total noob.

Check out the Wiki for starters,

and doc’s about ‘RPCs’

Thanks buddy !

The documentation Fredrum pointed out is a great place to start. Also, I wanted to post a few things that gave me issues when I first started with replication.

  • Make sure all actors are spawned from the Authority (server), otherwise the actor in the clients will think they’re the authority, the server will then replicate them down to the clients
  • Check the Role property of your actors to determine if the code is running on the Server or client
  • A good pattern to use is to do the work on the client AND the server so you don’t have to wait for lag, so for example if you have a DoSomething method:

void AMyActor::DoSomething()
if (Role < ROLE_Authority) {

// Do something, on the client AND eventually on the server too


bool AMyActor::Server_DoSomething_Validate()
return true;

void AMyActor::Server_DoSomething_Implementation()

i will ! thanks for the great support guys

I am having issues with the first thing you pointed out. I spawned an actor without authority and now it thinks it’s the server.

However in my component I have no idea how to check Role, the component doesn’t seem to have the Role variable. How did you handle this?

I used exact same pattern to replicate character rotation and unfortunately it does not replicate properly (Server pawn is updated on Client but Client is not updated on server). I followed A new, community-hosted Unreal Engine Wiki - Announcements and Releases - Unreal Engine Forums -> has something changed in new engine releases?


I have added

        GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, HasAuthority() ? TEXT("Attack Server!") :  TEXT("Attack Client!"));
        AddActorWorldOffset(GetActorForwardVector() * 100.0f);

to test why it won’t replicate properly and the texts on the screan are correct. Adding offset on server pawn works but on client pawn results in moving it but then moving it back to previous location. To be honest I don’t understand why

Ok I did manage to solve this but I wonder if there is more optimal way.

Right know I have multiple functions total ->

  • Server replicated (with validation)
  • Multicast replicated

then I check for authority and either run server or multicast function. I wonder if there is easier way to accopmlish it using UFunction headers?