Description
Inserts a component into the actor's OwnedComponents set, making it visible to GetComponents and other component-iteration APIs. This is called automatically by UActorComponent when it is attached to an actor.
Caveats & Gotchas
- • The component must already have its owner set to this actor (via `Component->SetOwner(this)` or by construction). The function asserts that `Component->GetOwner() == this` in debug builds.
- • Calling this directly is rarely necessary — `CreateDefaultSubobject` and `NewObject` + `RegisterComponent` handle registration automatically. Manually calling AddOwnedComponent without also calling `RegisterComponent` leaves the component in a partially initialised state.
- • There is no duplicate-checking beyond the TSet; calling with the same component twice is harmless (sets deduplicate), but it signals a logic error.
Signature
void AddOwnedComponent(UActorComponent* Component) Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| Component | UActorComponent* | The component to register with this actor's OwnedComponents set. | — |
Return Type
void Example
Manual registration (advanced, rarely needed) C++
// Typically done via RegisterComponent — shown here for clarity
UMyComponent* Comp = NewObject<UMyComponent>(this, UMyComponent::StaticClass());
Comp->SetupAttachment(RootComponent);
Comp->RegisterComponent(); // calls AddOwnedComponent internally Tags
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?