From 277e31c5dd53ec5992df6a2aa2ccdc017f879ebe Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Mon, 26 Jul 2021 21:32:00 +0200 Subject: [PATCH] Add helper `FindScript` and `FindActor` to `Actor` --- Source/Engine/Level/Actor.cs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Source/Engine/Level/Actor.cs b/Source/Engine/Level/Actor.cs index 7258f8514..fe24136d3 100644 --- a/Source/Engine/Level/Actor.cs +++ b/Source/Engine/Level/Actor.cs @@ -224,6 +224,26 @@ namespace FlaxEngine return script != null; } + /// + /// Tries to find the script of the given type in this actor hierarchy (checks this actor and all children hierarchy). + /// + /// Type of the object. + /// Script instance if found, null otherwise. + public T FindScript() where T : Script + { + return FindScript(typeof(T)) as T; + } + + /// + /// Tries to find the actor of the given type in this actor hierarchy (checks this actor and all children hierarchy). + /// + /// Type of the object. + /// Actor instance if found, null otherwise. + public T FindActor() where T : Actor + { + return FindActor(typeof(T)) as T; + } + /// /// Searches for all actors of a specific type in this actor children list. ///