RealDocs

AActor::GetActorClassDefaultComponentByName

function Engine Since 5.0
#include "GameFramework/Actor.h"
Access: public Specifiers: static

Description

Returns the CDO component with the given object name and type from the actor class, including Blueprint-added components. Useful when an actor has multiple components of the same type and you need a specific one by name.

Caveats & Gotchas

  • The name compared is the component's UObject name (the name shown in the Blueprint's component panel), not its display label. Typos or name changes break the lookup silently at runtime.
  • Blueprint component names can change when the Blueprint asset is renamed or duplicate-renamed in the editor. Hard-coding component names in C++ creates a fragile coupling to Blueprint authoring decisions.
  • Returns nullptr if no matching component is found; always null-check the result.

Signature

static const UActorComponent* GetActorClassDefaultComponentByName(const TSubclassOf<AActor>& InActorClass, const TSubclassOf<UActorComponent>& InComponentClass, FName InComponentName)

Parameters

Name Type Description Default
InActorClass const TSubclassOf<AActor>& The actor class whose CDO to inspect.
InComponentClass const TSubclassOf<UActorComponent>& Restrict the search to this component type.
InComponentName FName The object name of the component to find.

Return Type

const UActorComponent*

Example

Look up a named mesh component on a BP actor class C++
const UStaticMeshComponent* BodyMesh =
    Cast<UStaticMeshComponent>(
        AActor::GetActorClassDefaultComponentByName(
            MyActorClass,
            UStaticMeshComponent::StaticClass(),
            TEXT("BodyMesh")));
if (BodyMesh)
{
    UE_LOG(LogTemp, Log, TEXT("Found body mesh"));
}

Version History

Introduced in: 5.0

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.