diff --git a/Source/Engine/Level/Level.cpp b/Source/Engine/Level/Level.cpp index f24a853e3..db9812508 100644 --- a/Source/Engine/Level/Level.cpp +++ b/Source/Engine/Level/Level.cpp @@ -1613,13 +1613,18 @@ Array Level::GetActors(const MClass* type, bool activeOnly) return result; } -Array Level::GetScripts(const MClass* type) +Array Level::GetScripts(const MClass* type, Actor* root) { Array result; + CHECK_RETURN(type, result); ScopeLock lock(ScenesLock); - for (int32 i = 0; i < Scenes.Count(); i++) + + if (root) + ::GetScripts(type, root, result); + else for (int32 i = 0; i < Scenes.Count(); i++) ::GetScripts(type, Scenes[i], result); + return result; } diff --git a/Source/Engine/Level/Level.cs b/Source/Engine/Level/Level.cs index ae596e794..9efa496ef 100644 --- a/Source/Engine/Level/Level.cs +++ b/Source/Engine/Level/Level.cs @@ -66,7 +66,7 @@ namespace FlaxEngine { return FindActor(typeof(T)) as T; } - + /// /// Tries to find actor of the given type and name in all loaded scenes. /// @@ -77,7 +77,7 @@ namespace FlaxEngine { return FindActor(typeof(T), name) as T; } - + /// /// Tries to find actor of the given type and tag in a root actor or all loaded scenes. /// @@ -102,13 +102,14 @@ namespace FlaxEngine } /// - /// Finds all the scripts of the given type in all the loaded scenes. + /// Finds all the scripts of the given type in an actor or all the loaded scenes. /// /// Type of the object. + /// The root to find scripts. If null, will search in all scenes /// Found scripts list. - public static T[] GetScripts() where T : Script + public static T[] GetScripts(Actor root = null) where T : Script { - var scripts = GetScripts(typeof(T)); + var scripts = GetScripts(typeof(T), root); if (typeof(T) == typeof(Script)) return (T[])scripts; if (scripts.Length == 0) diff --git a/Source/Engine/Level/Level.h b/Source/Engine/Level/Level.h index b9c6b698a..44d9a3584 100644 --- a/Source/Engine/Level/Level.h +++ b/Source/Engine/Level/Level.h @@ -469,11 +469,12 @@ public: 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. + /// Finds all the scripts of the given type in an actor or all the loaded scenes. /// /// Type of the script to search for. Includes any scripts derived from the type. + /// The root to find scripts. If null, will search in all scenes /// Found scripts list. - API_FUNCTION() static Array GetScripts(API_PARAM(Attributes="TypeReference(typeof(Script))") const MClass* type); + API_FUNCTION() static Array GetScripts(API_PARAM(Attributes="TypeReference(typeof(Script))") const MClass* type, Actor* root = nullptr); /// /// Tries to find scene with given ID.