From 4386dc8774edcd7e30e3cdf4e3c64c6169317b20 Mon Sep 17 00:00:00 2001 From: Wojciech Figat Date: Wed, 15 Jun 2022 09:23:06 +0200 Subject: [PATCH] Add `Actor::GetOrAddChild` to C++ --- Source/Engine/Level/Actor.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Source/Engine/Level/Actor.h b/Source/Engine/Level/Actor.h index 872f4798b..5ba661a9e 100644 --- a/Source/Engine/Level/Actor.h +++ b/Source/Engine/Level/Actor.h @@ -222,6 +222,22 @@ public: return (T*)GetChild(T::GetStaticClass()); } + /// + /// Finds the child actor of the given type or creates a new one. + /// + /// The child actor. + template + T* GetOrAddChild() + { + T* result = (T*)GetChild(T::GetStaticClass()); + if (!result) + { + result = New(); + result->SetParent(this, false, false); + } + return result; + } + /// /// Gets the child actors of the given type. ///