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
+6 -2
View File
@@ -145,7 +145,7 @@ namespace GlitchyEngine.World
/**
* 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)
return null;
@@ -168,7 +168,11 @@ namespace GlitchyEngine.World
listEntity.ComponentMask[entry.Id] = true;
return (.)entry.Pool.Get(entity.Index);
T* component = (T*)entry.Pool.Get(entity.Index);
*component = T();
return component;
}
/**