diff --git a/Source/Engine/Level/Actor.cpp b/Source/Engine/Level/Actor.cpp index addb4861e..fa0b10af1 100644 --- a/Source/Engine/Level/Actor.cpp +++ b/Source/Engine/Level/Actor.cpp @@ -1339,6 +1339,21 @@ bool Actor::IsPrefabRoot() const return _isPrefabRoot != 0; } +Actor* Actor::GetPrefabRoot() +{ + if (!this->HasPrefabLink()) + { + return NULL; + } + + Actor* result = this; + while (!result == NULL && !result->IsPrefabRoot()) + { + result = result->GetParent(); + } + return result; +} + Actor* Actor::FindActor(const StringView& name) const { Actor* result = nullptr; diff --git a/Source/Engine/Level/Actor.h b/Source/Engine/Level/Actor.h index 0ce9a0dbc..6aad2f481 100644 --- a/Source/Engine/Level/Actor.h +++ b/Source/Engine/Level/Actor.h @@ -739,6 +739,12 @@ public: /// API_PROPERTY() bool IsPrefabRoot() const; + /// + /// Gets the root of the prefab this actor is attached to. + /// + /// The root prefab object, or null if this actor is not a prefab. + API_FUNCTION() Actor* GetPrefabRoot(); + public: /// /// Tries to find the actor with the given name in this actor hierarchy (checks this actor and all children hierarchy).