From 3824b19c8b4aab7ad4ba2e53fc8de8805d6f0e05 Mon Sep 17 00:00:00 2001 From: Menotdan <32620310+Menotdan@users.noreply.github.com> Date: Thu, 16 Nov 2023 23:46:44 -0500 Subject: [PATCH] Added Actor.GetPrefabRoot() --- Source/Engine/Level/Actor.cpp | 15 +++++++++++++++ Source/Engine/Level/Actor.h | 6 ++++++ 2 files changed, 21 insertions(+) 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).