From 1cc37ee1685cb1bee99264cc12ec0004af85f266 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20L=C3=BCbe=C3=9F?= Date: Thu, 30 Dec 2021 16:18:22 +0100 Subject: [PATCH] Run default constructor when assigning component --- GlitchyEngine/src/World/EcsWorld.bf | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/GlitchyEngine/src/World/EcsWorld.bf b/GlitchyEngine/src/World/EcsWorld.bf index e2b42bb..2d73c56 100644 --- a/GlitchyEngine/src/World/EcsWorld.bf +++ b/GlitchyEngine/src/World/EcsWorld.bf @@ -145,7 +145,7 @@ namespace GlitchyEngine.World /** * Assigns a component of type T to the specified entity and returns it. */ - public T* AssignComponent(Entity entity) where T : struct + public T* AssignComponent(Entity entity) where T : struct, new { if(entity.Index > _entities.Count) return null; @@ -167,8 +167,12 @@ namespace GlitchyEngine.World // return null; listEntity.ComponentMask[entry.Id] = true; - - return (.)entry.Pool.Get(entity.Index); + + T* component = (T*)entry.Pool.Get(entity.Index); + + *component = T(); + + return component; } /**