What's the preferred way to replicate ActorComponent?

The 4.27 docs says we can just AActorComponent::SetIsReplicated(true) if we want to replicate the component.

While this seems work in UE5 but I can not find it describes in docs. The latest docs shows other ways to replicate Subobjects.

If all the approaches work in UE 5, which is the preferred way? How to decide which one to use ?

SubObjects are for custom c++ objects i believe,

SetIsReplicated is fine for ACs

1 Like

Just browsed the source code and reread the docs for some time. Here’s what I’ve got to know if you are interested.

First of all UActorComponents are also UObjects. The ways to replicate UObjects also apply to them as the docs say.

If you call AActorComponent::SetIsReplicated(true), it basically adds the component to its owner’s (an actor) ReplicatedComponents for replication.

If you want to use the “new methods” (subobjects list) to replicate, you’ll need to set bReplicateUsingRegisteredSubObjectList to true. Let’s see the comments on this variable, which is false by default:

When true the replication system will only replicate the registered subobjects and the replicated actor components list

When false the replication system will instead call the virtual ReplicateSubobjects() function where the subobjects and actor components need to be manually replicated.

The default implementation of ReplicateSubobjects (only called when bReplicateUsingRegisteredSubObjectList is false) iterates through ReplicatedComponents and call Channel->ReplicateSubobject to make them replicated. You can read that this method is old, deprecated somehow from their comments and symbol names. You’ll need to override it if you want to replicate other subobjects.

If you want to use the new method, just bReplicateUsingRegisteredSubObjectList to true and use AddReplicatedSubObject to add them to the ReplicatedSubObjects.

But actually in AActor::BeginReplication, both ReplicatedSubObjects and ReplicatedComponents are iterated.

So I guess for ActorComponents it’s okay to call AActorComponent::SetIsReplicated(true) no matter which method you use.

You can find the declarations of the stuff mentioned in Actor.h and ActorComponent.h. Some of the definitions are in ActorReplicationBridge.cpp.

there is an even newer system coming called ‘Iris’ so just do whats best for your game now :slight_smile:

Yeah I’ve seen that in the docs😂