RealDocs

AActor::AddComponentByClass

function Engine Blueprint Since 4.26
#include "GameFramework/Actor.h"
Access: public Specifiers: UFUNCTIONBlueprintCallable

Description

Blueprint-internal function that creates a component from a class reference rather than a named template, powering the 'Add Component by Class' Blueprint node. Like AddComponent, this should not be called from C++ game code.

Caveats & Gotchas

  • The AllowAbstract=false meta restriction is enforced in Blueprint only — abstract classes can still be passed in C++, which will result in a failed NewObject call and a nullptr return.
  • This is a Blueprint-internal function (marked 'DO NOT CALL MANUALLY'). In C++ use NewObject<T>() + RegisterComponent() for runtime component addition.
  • Unlike AddComponent, there is no template lookup — it instantiates the class directly. Expose-on-spawn properties are not supported through this path unless you use bDeferredFinish=true and set them before calling FinishAddComponent.

Signature

ENGINE_API UActorComponent* AddComponentByClass(UPARAM(meta = (AllowAbstract = "false")) TSubclassOf<UActorComponent> Class, bool bManualAttachment, const FTransform& RelativeTransform, bool bDeferredFinish)

Parameters

Name Type Description Default
Class TSubclassOf<UActorComponent> The concrete component class to instantiate.
bManualAttachment bool If false, auto-attaches to root. If true, caller handles attachment.
RelativeTransform const FTransform& Relative transform to apply when auto-attaching.
bDeferredFinish bool If true, delays final registration until FinishAddComponent() is called.

Return Type

UActorComponent*

Example

C++ equivalent pattern (preferred over AddComponentByClass) C++
// AddComponentByClass() is for Blueprint nodes. In C++:
UPointLightComponent* Light = NewObject<UPointLightComponent>(this);
Light->SetupAttachment(GetRootComponent());
Light->SetRelativeTransform(RelativeTransform);
Light->RegisterComponent();

Version History

Introduced in: 4.26

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.