Network Replication Events And Relevance Table

Which Network Type Should I Use? Author: () For the official replication information, see: Sometimes it can be confusing which type of replication event you need for a particular situation. This ta...

Updated over 4 years ago Edit Page Revisions

Which Network Type Should I Use?

Author: ()

For the official replication information, see:

Sometimes it can be confusing which type of replication event you need for a particular situation. This table assumes that all communications are replicated with the Reliable flag. "Instant" means... ASAP, other things may be more important.

Replication Type | Caller | Recipient | Relevant | Not Relevant | Other Notes

------------------- | -------- | -------------- | -------- | ------------- | -------------------------------------------------------------------

Server | 1 Client | Server | Instant | N/A | Used to ask server for permission (i.e. use an item)

Client | Server | 1 Client | Instant | N/A | 1 client executes a function

NetMulticast | Server | Clients/Server | Instant | Never | Many clients execute a function (i.e. temp things, bomb explosion)

Replicated | Server | Clients/Server | Instant | When Relevant | Server has changed a basic property, like HP

ReplicatedUsing | Server | Clients | Instant | When Relevant | Clients execute function on property updates (i.e. update the UI).

??? | Server | Clients | Instant | Instant | Iterate controllers on server to call Client (see next section)

Notify All Players Instantly

If you want to have the server INSTANTLY tell EVERY client, you can iterate PlayerControllers and call a Client function.

for (FConstControllerIterator It = GetWorld()->GetControllerIterator(); It; ++It)
{
    AMyPlayerController* PlayerController = Cast(*It);
    
    if (PlayerController)
        PlayerController->Client_SendRoundEndEvent(bIsWinner);
}

You often see code like this in the GameMode Actor (which exists on the server only), but it can be useful in other cases.

Common Actors Which are Always Relevant

Common Actors that are ALWAYS relevant:

  • GameState
  • PlayerState (Every client has ALL players)
  • PlayerController (Every client generally has 1, their own)

This means you can use a NetMulticast in GameState and PlayerState(s) instead of the above code.

See:

Events on Listen and Dedicated Servers

  • NetMulticast executes automatically on Listen and Dedicated Servers
    • But, ReplicatedUsing, a server must manually call the OnRep_*() function.
  • Client executes as expected for a Listen Server's "Client"
    • But, Server on a Listen Server is not necessary, example
void AMyActor::DoSomething()
{
    if (!HasAuthority())             // No Authority == We are a client
    {
        Server_DoSomething();        // So, we ask permission, 
        return;                      // or at least have this execute on server 
    }                                // (so the official state knows about it).
    
    // We're the server, actually do it
}
       
void AMyActor::Server_DoSomething_Implementation()  // note: _Implementation(),
{                                                   // we can also have _Validate()
    DoSomething();                                  // which kicks player on false
}

Replicated Relevance Conditions

Replicated values can have relevance based on certain conditions, such as:

  • COND_OwnerOnly
  • COND_SkipOwner
  • COND_InitialOnly
  • More...

See:

ReplicatedUsing Relevance Conditions

Similar to Replicated, but this fires a function. In addition to the conditions for Replicated, you can use the following conditions:

  • REPNOTIFY_OnChanged - Only replicate if value has changed. It may be stale (i.e. it changed, and changed back).
  • REPNOTIFY_Always - Value is still same on the client (but stale), but fire callback.

See: