Composite Pattern in Pure ECS,Composite Pattern in Unity ECS
I setup to create a small customization tool in pure Unity ECS.
The basics would be to do it in a classic Composite Pattern style. Start with a part of type "chassis", this chassis has slots, those slots can themselves contain Parts of different types and different sizes, and so on and so forth.
I've done it easily in OOP/Gameobjects.
- Each part is a gameobject with a script.
- Each slot is a child of the part and is referenced in a List in the Parts script.
- Both the Part and the Slots have scripts containing info about their constraints (the size and type of part that they are/can fit).
It's been much more difficult to do it in ECS though.
Each gameobject part is now an entity that contains a Renderer, a Translate and a PartComponent. The PartComponent contains the data about the Size and Type of Part.
Each empty gameobject Slot is now a SlotComponent that contains a float3 and a size and type of Part that it can fit.
Problem is I cannot have a list of SlotComponent in the PartComponent (Error : "List neither primitive nor blittable").
I thought that I maybe could have all the SlotComponents directly in the Part Entity itself, but I don't know if Entities support multiples instances of the same component within them, furthermore It doesn't seem you can access these. (There is SceneManager.GetComponentData(entity) that return a (/the ?) Component of type T within entity, but no SceneManager.GetComponentSData(entity) that could return me a List of components of type T, within entity.
Is there a work around ? Did I get so used to my OOP Hammer that I see ECS as a nail ?
I'm not sure if I'm clear, but I'm pulling my hair out trying to wrap my head around this new paradigm. Any help would be greatly appreciated. Thank you.
Your answer
