AActor::HasValidRootComponent
#include "GameFramework/Actor.h"
Access: public
Description
Returns true if this actor has a root component that is fully registered with the world. A root component can exist (non-null pointer) but still be unregistered, in which case this returns false.
Caveats & Gotchas
- • More reliable than a null check on GetRootComponent() for guarding transform operations: an unregistered but non-null root component can cause assertion failures if SetActorLocation() is called on it.
- • Returns false during deferred spawn or before RegisterAllComponents() has completed. Prefer this over checking GetRootComponent() != nullptr when the timing of registration is uncertain.
Signature
ENGINE_API bool HasValidRootComponent() const; Return Type
bool Example
Safe transform assignment after spawn C++
AActor* Spawned = GetWorld()->SpawnActor<AActor>(MyClass, SpawnTransform);
if (Spawned && Spawned->HasValidRootComponent())
{
Spawned->SetActorLocation(TargetLocation);
} Tags
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?