From af5f3cbd95e8c46762fac91cf8632f4b1de717ed Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Thu, 15 Dec 2022 08:18:09 -0600 Subject: [PATCH 1/3] Return null if type is abstract but trying to be added as an actor or script --- Source/Engine/Level/Actor.cs | 15 +++++++++++++++ Source/Engine/Level/Actor.h | 4 ++++ 2 files changed, 19 insertions(+) diff --git a/Source/Engine/Level/Actor.cs b/Source/Engine/Level/Actor.cs index 936d38565..cd774fca6 100644 --- a/Source/Engine/Level/Actor.cs +++ b/Source/Engine/Level/Actor.cs @@ -123,6 +123,9 @@ namespace FlaxEngine /// The child actor. public Actor AddChild(Type type) { + if (type.IsAbstract) + return null; + var result = (Actor)New(type); result.SetParent(this, false, false); return result; @@ -135,6 +138,9 @@ namespace FlaxEngine /// The child actor. public T AddChild() where T : Actor { + if (typeof(T).IsAbstract) + return null; + var result = New(); result.SetParent(this, false, false); return result; @@ -172,6 +178,9 @@ namespace FlaxEngine var result = GetChild(); if (result == null) { + if (typeof(T).IsAbstract) + return null; + result = New(); result.SetParent(this, false, false); } @@ -185,6 +194,9 @@ namespace FlaxEngine /// The created script instance, null otherwise. public Script AddScript(Type type) { + if (type.IsAbstract) + return null; + var script = (Script)New(type); script.Parent = this; return script; @@ -197,6 +209,9 @@ namespace FlaxEngine /// The created script instance, null otherwise. public T AddScript() where T : Script { + if (typeof(T).IsAbstract) + return null; + var script = New(); script.Parent = this; return script; diff --git a/Source/Engine/Level/Actor.h b/Source/Engine/Level/Actor.h index e9ad7793c..e108b0756 100644 --- a/Source/Engine/Level/Actor.h +++ b/Source/Engine/Level/Actor.h @@ -227,6 +227,10 @@ public: T* result = (T*)GetChild(T::GetStaticClass()); if (!result) { + const MClass* type = T::GetStaticClass(); + if (type->IsAbstract()) + return nullptr; + result = New(); result->SetParent(this, false, false); } From c3f23d13902581ad5ae7c8268660e72c1f453393 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Thu, 15 Dec 2022 08:49:52 -0600 Subject: [PATCH 2/3] Added abstract check to spawning actor --- Source/Engine/Level/Level.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Source/Engine/Level/Level.cpp b/Source/Engine/Level/Level.cpp index 98ad5a694..485b1a3b6 100644 --- a/Source/Engine/Level/Level.cpp +++ b/Source/Engine/Level/Level.cpp @@ -177,6 +177,12 @@ bool LevelImpl::spawnActor(Actor* actor, Actor* parent) return true; } + if (actor->GetType().ManagedClass->IsAbstract()) + { + Log::Exception(TEXT("Cannot spawn abstract actor type.")); + return true; + } + if (actor->Is()) { // Spawn scene From 66771775341b94d90080da6c70f4cc233d39032e Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Thu, 15 Dec 2022 08:52:37 -0600 Subject: [PATCH 3/3] Removed variable MClass --- Source/Engine/Level/Actor.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Source/Engine/Level/Actor.h b/Source/Engine/Level/Actor.h index e108b0756..ec52a8c74 100644 --- a/Source/Engine/Level/Actor.h +++ b/Source/Engine/Level/Actor.h @@ -227,8 +227,7 @@ public: T* result = (T*)GetChild(T::GetStaticClass()); if (!result) { - const MClass* type = T::GetStaticClass(); - if (type->IsAbstract()) + if (T::GetStaticClass()->IsAbstract()) return nullptr; result = New();