Add Actor::GetOrAddChild to C++

This commit is contained in:
Wojciech Figat
2022-06-15 09:23:06 +02:00
parent fc96620045
commit 4386dc8774

View File

@@ -222,6 +222,22 @@ public:
return (T*)GetChild(T::GetStaticClass()); return (T*)GetChild(T::GetStaticClass());
} }
/// <summary>
/// Finds the child actor of the given type or creates a new one.
/// </summary>
/// <returns>The child actor.</returns>
template<typename T>
T* GetOrAddChild()
{
T* result = (T*)GetChild(T::GetStaticClass());
if (!result)
{
result = New<T>();
result->SetParent(this, false, false);
}
return result;
}
/// <summary> /// <summary>
/// Gets the child actors of the given type. /// Gets the child actors of the given type.
/// </summary> /// </summary>