From 875dd30d57dd064498032da1d1b1a2ab7f8a5faf Mon Sep 17 00:00:00 2001 From: Ruan Lucas <79365912+RuanLucasGD@users.noreply.github.com> Date: Wed, 21 Jun 2023 21:27:38 -0400 Subject: [PATCH 1/2] add optional parameter to find only active actors on Level.FinActors(tag) --- Source/Engine/Level/Level.cpp | 12 +++++++----- Source/Engine/Level/Level.h | 3 ++- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/Source/Engine/Level/Level.cpp b/Source/Engine/Level/Level.cpp index ae617b980..7b6a3844f 100644 --- a/Source/Engine/Level/Level.cpp +++ b/Source/Engine/Level/Level.cpp @@ -740,12 +740,14 @@ Actor* FindActorRecursive(Actor* node, const Tag& tag) return result; } -void FindActorsRecursive(Actor* node, const Tag& tag, Array& result) +void FindActorsRecursive(Actor* node, const Tag& tag, const bool activeOnly, Array& result) { + if (activeOnly && !node->GetIsActive()) + return; if (node->HasTag(tag)) result.Add(node); for (Actor* child : node->Children) - FindActorsRecursive(child, tag, result); + FindActorsRecursive(child, tag, activeOnly, result); } void FindActorsRecursiveByParentTags(Actor* node, const Array& tags, Array& result) @@ -785,19 +787,19 @@ void FindActorRecursive(Actor* node, const Tag& tag, Array& result) FindActorRecursive(child, tag, result); } -Array Level::FindActors(const Tag& tag, Actor* root) +Array Level::FindActors(const Tag& tag, const bool activeOnly, Actor* root) { PROFILE_CPU(); Array result; if (root) { - FindActorsRecursive(root, tag, result); + FindActorsRecursive(root, tag, activeOnly, result); } else { ScopeLock lock(ScenesLock); for (Scene* scene : Scenes) - FindActorsRecursive(scene, tag, result); + FindActorsRecursive(scene, tag, activeOnly, result); } return result; } diff --git a/Source/Engine/Level/Level.h b/Source/Engine/Level/Level.h index e27b81bb9..a7524b40a 100644 --- a/Source/Engine/Level/Level.h +++ b/Source/Engine/Level/Level.h @@ -494,9 +494,10 @@ public: /// Tries to find the actors with the given tag (returns all found). /// /// The tag of the actor to search for. + /// Find only active actors. /// The custom root actor to start searching from (hierarchical), otherwise null to search all loaded scenes. /// Found actors or empty if none. - API_FUNCTION() static Array FindActors(const Tag& tag, Actor* root = nullptr); + API_FUNCTION() static Array FindActors(const Tag& tag, const bool activeOnly = false, Actor* root = nullptr); /// /// Search actors using a parent parentTag. From 072d70722c640b563270c91070f37584c151ffb7 Mon Sep 17 00:00:00 2001 From: Ruan Lucas <79365912+RuanLucasGD@users.noreply.github.com> Date: Wed, 21 Jun 2023 21:38:22 -0400 Subject: [PATCH 2/2] add optional parameter to find only active actors on Level.FindActorsByParentTag --- Source/Engine/Level/Level.cpp | 14 ++++++++------ Source/Engine/Level/Level.h | 3 ++- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Source/Engine/Level/Level.cpp b/Source/Engine/Level/Level.cpp index 7b6a3844f..ab8a9bbfe 100644 --- a/Source/Engine/Level/Level.cpp +++ b/Source/Engine/Level/Level.cpp @@ -750,8 +750,10 @@ void FindActorsRecursive(Actor* node, const Tag& tag, const bool activeOnly, Arr FindActorsRecursive(child, tag, activeOnly, result); } -void FindActorsRecursiveByParentTags(Actor* node, const Array& tags, Array& result) +void FindActorsRecursiveByParentTags(Actor* node, const Array& tags, const bool activeOnly, Array& result) { + if (activeOnly && !node->GetIsActive()) + return; for (Tag tag : tags) { if (node->HasTag(tag)) @@ -761,7 +763,7 @@ void FindActorsRecursiveByParentTags(Actor* node, const Array& tags, Array< } } for (Actor* child : node->Children) - FindActorsRecursiveByParentTags(child, tags, result); + FindActorsRecursiveByParentTags(child, tags, activeOnly, result); } Actor* Level::FindActor(const Tag& tag, Actor* root) @@ -804,7 +806,7 @@ Array Level::FindActors(const Tag& tag, const bool activeOnly, Actor* ro return result; } -Array Level::FindActorsByParentTag(const Tag& parentTag, Actor* root) +Array Level::FindActorsByParentTag(const Tag& parentTag, const bool activeOnly, Actor* root) { PROFILE_CPU(); Array result; @@ -816,19 +818,19 @@ Array Level::FindActorsByParentTag(const Tag& parentTag, Actor* root) } if (subTags.Count() == 1) { - result = FindActors(subTags[0], root); + result = FindActors(subTags[0], activeOnly, root); return result; } if (root) { - FindActorsRecursiveByParentTags(root, subTags, result); + FindActorsRecursiveByParentTags(root, subTags, activeOnly, result); } else { ScopeLock lock(ScenesLock); for (Scene* scene : Scenes) - FindActorsRecursiveByParentTags(scene, subTags, result); + FindActorsRecursiveByParentTags(scene, subTags, activeOnly, result); } return result; diff --git a/Source/Engine/Level/Level.h b/Source/Engine/Level/Level.h index a7524b40a..9a041bda9 100644 --- a/Source/Engine/Level/Level.h +++ b/Source/Engine/Level/Level.h @@ -503,9 +503,10 @@ public: /// Search actors using a parent parentTag. /// /// The tag to search actors with subtags belonging to this tag + /// Find only active actors. /// The custom root actor to start searching from (hierarchical), otherwise null to search all loaded scenes. /// Returns all actors that have subtags belonging to the given parent parentTag - API_FUNCTION() static Array FindActorsByParentTag(const Tag& parentTag, Actor* root = nullptr); + API_FUNCTION() static Array FindActorsByParentTag(const Tag& parentTag, const bool activeOnly = false, Actor* root = nullptr); private: // Actor API