RealDocs

AActor::CreateComponentFromTemplate

function Engine Since 4.0
#include "GameFramework/Actor.h"
Access: public

Description

Instantiates a new component by duplicating a template object, used during Blueprint construction script execution to stamp out component instances.

Caveats & Gotchas

  • This creates the component in memory but does NOT register it — you must call FinishAndRegisterComponent afterwards for it to participate in the actor lifecycle.
  • The template must already exist as a valid archetype associated with the actor's class; passing an arbitrary component as a template can produce incorrectly parented instances.

Signature

ENGINE_API UActorComponent* CreateComponentFromTemplate(UActorComponent* Template, const FName InName = NAME_None );

Parameters

Name Type Description Default
Template UActorComponent* The component template (archetype) to instantiate from.
InName const FName Desired name for the new component instance. Uses an auto-generated name if NAME_None. NAME_None

Return Type

UActorComponent*

Example

Create a component instance from a class default template C++
// Retrieve the CDO template and instantiate it
UStaticMeshComponent* Template = GetDefault<AMyActor>()->FindComponentByClass<UStaticMeshComponent>();
if (Template)
{
    UActorComponent* NewComp = CreateComponentFromTemplate(Template, TEXT("MyMesh"));
    FinishAndRegisterComponent(NewComp);
}

Version History

Introduced in: 4.0

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.