AActor::GetActorClassDefaultComponent
#include "GameFramework/Actor.h"
Access: public
Specifiers: static
Description
Returns the first CDO component of a given type from the actor class, including Blueprint-added components. Returns nullptr if none is found. Use the templated overload `GetActorClassDefaultComponent<T>()` to avoid an explicit cast.
Caveats & Gotchas
- • Returns only the first match. If an actor has multiple components of the same type and order matters, use GetActorClassDefaultComponents to retrieve all of them.
- • The returned pointer is a const reference to a CDO template object. Storing it across Blueprint recompiles or hot-reload events may result in a dangling pointer in the editor.
Signature
static const UActorComponent* GetActorClassDefaultComponent(const TSubclassOf<AActor>& InActorClass, const TSubclassOf<UActorComponent>& InComponentClass) Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| InActorClass | const TSubclassOf<AActor>& | The actor class whose CDO to inspect. | — |
| InComponentClass | const TSubclassOf<UActorComponent>& | The component type to find. | — |
Return Type
const UActorComponent* Example
Check if a class has a skeletal mesh component by default C++
const USkeletalMeshComponent* SkelMesh =
AActor::GetActorClassDefaultComponent<USkeletalMeshComponent>(MyActorClass);
if (SkelMesh)
{
UE_LOG(LogTemp, Log, TEXT("Default skeleton: %s"), *GetNameSafe(SkelMesh->GetSkeletalMeshAsset()));
} Tags
Version History
Introduced in: 5.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?