setup-replication
Configure an actor class for network replication in multiplayer UE games.
SKILL.mdUnrealEngine/skills/setup-replication/SKILL.md
GitHubSkill: Setup Actor Replication
Description
Configure an actor class for network replication in multiplayer UE games.
Arguments
- {{arg}}: Actor class to configure replication for
Steps
Option A: Blueprint Native Tool Routes (In-Editor Asset Configuration)
Configure Actor Network Replication (
configure_actor_replication): Useconfigure_actor_replicationto set network replication defaults on a Blueprint actor CDO:{ "TargetAsset": "/Game/Blueprints/BP_NetworkPawn", "bReplicates": true, "bReplicateMovement": true, "NetDormancy": "DORM_Never", "NetUpdateFrequency": 100.0, "NetPriority": 1.0 }Configure Variable Replication & RepNotify (
set_variable_replication):Standard Variable Replication:
{ "TargetAsset": "/Game/Blueprints/BP_NetworkPawn", "VariableName": "Health", "ReplicationType": "Replicated", "ReplicationCondition": "COND_None" }Replication with RepNotify Callback: Setting
ReplicationTypeto"RepNotify"and specifyingRepNotifyFuncwill automatically generate theOnRep_Shieldcallback graph:{ "TargetAsset": "/Game/Blueprints/BP_NetworkPawn", "VariableName": "Shield", "ReplicationType": "RepNotify", "RepNotifyFunc": "OnRep_Shield", "ReplicationCondition": "COND_None" }Replication with Lifetime Condition (Owner Only / Skip Owner):
{ "TargetAsset": "/Game/Blueprints/BP_NetworkPawn", "VariableName": "SecretData", "ReplicationType": "Replicated", "ReplicationCondition": "COND_OwnerOnly" }
Option B: C++ Code Patterns (Base Class Implementation)
Constructor: Enable replication
bReplicates = true; SetReplicateMovement(true);Add GetLifetimeReplicatedProps:
void {{arg}}::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const { Super::GetLifetimeReplicatedProps(OutLifetimeProps); DOREPLIFETIME({{arg}}, Health); DOREPLIFETIME_CONDITION({{arg}}, bIsVisible, COND_OwnerOnly); }Mark properties for replication:
Standard Replication (No callback):
UPROPERTY(Replicated) float Health;Replication with RepNotify Callback (Client side effect):
UPROPERTY(ReplicatedUsing=OnRep_Shield) float Shield; UFUNCTION() void OnRep_Shield(float OldShield);Server RPCs for player actions:
UFUNCTION(Server, Reliable) void ServerDoAction();Required include:
#include "Net/UnrealNetwork.h"
Python API Tip (UE 5.8)
- To set replication on a Blueprint CDO via Unreal Python:
cdo = bp.get_editor_property('generated_class').get_default_object(), callcdo.set_replicates(True), and compile withunreal.BlueprintEditorLibrary.compile_blueprint(bp).