AActor::AddActorComponentReplicatedSubObject
#include "GameFramework/Actor.h"
Access: public
Description
Registers a UObject as a replicated sub-object owned by a specific actor component, so its UPROPERTY fields replicate along with that component's replication lifecycle.
Caveats & Gotchas
- • The OwnerComponent must itself be in the actor's replicated components list. If the component is not replicating, this sub-object will also not replicate.
- • You must call RemoveActorComponentReplicatedSubObject before destroying either the sub-object or its owner component to avoid dangling pointer issues.
- • Do not call this from within a component's constructor — the actor may not have finished registering the component yet. Call it in BeginPlay or later.
Signature
ENGINE_API void AddActorComponentReplicatedSubObject(UActorComponent* OwnerComponent, UObject* SubObject, ELifetimeCondition NetCondition = COND_None) Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| OwnerComponent | UActorComponent* | The component that owns this sub-object. | — |
| SubObject | UObject* | The UObject to register for replication under the given component. | — |
| NetCondition | ELifetimeCondition | Optional condition for which connections replicate this sub-object. Defaults to COND_None. | COND_None |
Return Type
void Example
Register a sub-object with its owning component C++
void AMyActor::BeginPlay()
{
Super::BeginPlay();
if (HasAuthority())
{
StatusEffect = NewObject<UStatusEffect>(this);
AddActorComponentReplicatedSubObject(StatusComponent, StatusEffect);
}
} See Also
Tags
Version History
Introduced in: 5.1
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?