diff --git a/Source/Engine/Level/Level.cpp b/Source/Engine/Level/Level.cpp index 39db728bb..ccbe7a59a 100644 --- a/Source/Engine/Level/Level.cpp +++ b/Source/Engine/Level/Level.cpp @@ -1617,13 +1617,16 @@ 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++) - ::GetScripts(type, type->IsInterface(), Scenes[i], result); + const bool isInterface = type->IsInterface(); + if (root) + ::GetScripts(type, isInterface, root, result); + else for (int32 i = 0; i < Scenes.Count(); i++) + ::GetScripts(type, isInterface, 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 c79abe784..d68336beb 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.