diff --git a/Source/Engine/Level/Level.cpp b/Source/Engine/Level/Level.cpp index cfdf11a6f..6770961fb 100644 --- a/Source/Engine/Level/Level.cpp +++ b/Source/Engine/Level/Level.cpp @@ -1564,12 +1564,14 @@ Script* Level::FindScript(const MClass* type) namespace { - void GetActors(const MClass* type, Actor* actor, Array& result) + void GetActors(const MClass* type, Actor* actor, bool activeOnly, Array& result) { + if (activeOnly && !actor->GetIsActive()) + return; if (actor->GetClass()->IsSubClassOf(type)) result.Add(actor); for (auto child : actor->Children) - GetActors(type, child, result); + GetActors(type, child, activeOnly, result); } void GetScripts(const MClass* type, Actor* actor, Array& result) @@ -1582,13 +1584,13 @@ namespace } } -Array Level::GetActors(const MClass* type) +Array Level::GetActors(const MClass* type, bool activeOnly) { Array result; CHECK_RETURN(type, result); ScopeLock lock(ScenesLock); for (int32 i = 0; i < Scenes.Count(); i++) - ::GetActors(type, Scenes[i], result); + ::GetActors(type, Scenes[i], activeOnly, result); return result; } diff --git a/Source/Engine/Level/Level.cs b/Source/Engine/Level/Level.cs index 1e8524f2c..b43d9e91a 100644 --- a/Source/Engine/Level/Level.cs +++ b/Source/Engine/Level/Level.cs @@ -119,10 +119,11 @@ namespace FlaxEngine /// Finds all the actors of the given type in all the loaded scenes. /// /// Type of the object. + /// Finds only active actors. /// Found actors list. - public static T[] GetActors() where T : Actor + public static T[] GetActors(bool activeOnly = false) where T : Actor { - var actors = GetActors(typeof(T)); + var actors = GetActors(typeof(T), activeOnly); var result = new T[actors.Length]; for (int i = 0; i < actors.Length; i++) result[i] = actors[i] as T; diff --git a/Source/Engine/Level/Level.h b/Source/Engine/Level/Level.h index e09f8e376..0e7ff04c9 100644 --- a/Source/Engine/Level/Level.h +++ b/Source/Engine/Level/Level.h @@ -460,8 +460,9 @@ public: /// Finds all the actors of the given type in all the loaded scenes. /// /// Type of the actor to search for. Includes any actors derived from the type. + /// Finds only active actors in the scene. /// Found actors list. - API_FUNCTION() static Array GetActors(API_PARAM(Attributes="TypeReference(typeof(Actor))") const MClass* type); + API_FUNCTION() static Array GetActors(API_PARAM(Attributes="TypeReference(typeof(Actor))") const MClass* type, bool activeOnly = false); /// /// Finds all the scripts of the given type in all the loaded scenes.