AActor::AddInstanceComponent
#include "GameFramework/Actor.h"
Access: public
Description
Adds a component to the actor's InstanceComponents array, which tracks components added at runtime rather than defined in the class defaults. Use this when dynamically attaching components outside of the constructor.
Caveats & Gotchas
- • This only adds the component to the tracking array — it does not register, initialize, or attach the component. You must call RegisterComponent() and set up attachment separately.
- • Components added via this function are serialized with the actor instance (the UPROPERTY is marked Instanced), so they persist across save/load but will not appear on CDO-derived instances unless explicitly added again.
Signature
ENGINE_API void AddInstanceComponent(UActorComponent* Component) Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| Component | UActorComponent* | The component to add to the instance components array. | — |
Return Type
void Example
Dynamically add a point light component at runtime C++
UPointLightComponent* Light = NewObject<UPointLightComponent>(this, UPointLightComponent::StaticClass());
Light->SetupAttachment(RootComponent);
Light->RegisterComponent();
AddInstanceComponent(Light); Tags
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?