UActorComponent::GetOwner
#include "Components/ActorComponent.h"
Access: public
Specifiers: UFUNCTIONBlueprintCallableconst
Description
Returns the AActor that owns this component by following the Outer chain. This is the primary way to access the owning actor from within a component.
Caveats & Gotchas
- • Returns null if the component has no valid outer or if it has not yet been attached to an actor. Always null-check the result when calling from contexts where ownership may not be established (e.g., early construction or CDO).
- • A templated overload exists — GetOwner<T>() — that casts to a specific actor type and returns nullptr if the cast fails. Prefer it over manually casting the result to avoid double-casts.
Signature
UFUNCTION(BlueprintCallable, Category="Components", meta=(Keywords = "Actor Owning Parent"))
AActor* GetOwner() const Return Type
AActor* Examples
Get the owning actor and access its properties C++
void UMyComponent::BeginPlay()
{
Super::BeginPlay();
if (AActor* Owner = GetOwner())
{
UE_LOG(LogTemp, Log, TEXT("Component owned by: %s"), *Owner->GetName());
}
} Get the owning actor as a specific type C++
AMyCharacter* Character = GetOwner<AMyCharacter>();
if (Character)
{
Character->PlayAnimation();
} See Also
Tags
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?