Run default constructor when assigning component

This commit is contained in:
Simon Lübeß
2021-12-30 16:18:22 +01:00
parent f4d64b15fa
commit 1cc37ee168
+7 -3
View File
@@ -145,7 +145,7 @@ namespace GlitchyEngine.World
/** /**
* Assigns a component of type T to the specified entity and returns it. * Assigns a component of type T to the specified entity and returns it.
*/ */
public T* AssignComponent<T>(Entity entity) where T : struct public T* AssignComponent<T>(Entity entity) where T : struct, new
{ {
if(entity.Index > _entities.Count) if(entity.Index > _entities.Count)
return null; return null;
@@ -167,8 +167,12 @@ namespace GlitchyEngine.World
// return null; // return null;
listEntity.ComponentMask[entry.Id] = true; listEntity.ComponentMask[entry.Id] = true;
return (.)entry.Pool.Get(entity.Index); T* component = (T*)entry.Pool.Get(entity.Index);
*component = T();
return component;
} }
/** /**