I’m trying to learn DOTS and ECS with a very simple project, but I think I’m fundamentally misunderstanding some structural things because it seems to be impossible to do something incredibly simple.
I have a ‘soldier’ object made up of 3 meshes-- body, with two children: left arm & right arm. All I want is to manually animate this guy so that the whole body bounces up and down, and the arms each swing. Just need to be modifying 1 Translation, and 2 Rotations, derived from one shared animationTimer (that increments in a system based on deltaTime)
So I built a prefab with the following structure:
[Root Node: Skeleton_Data authored component, ConvertToEntity component]
.[Body, with a Render Mesh & Filter]
…[Left arm, with a Render Mesh & Filter]
…[Right arm, with a Render Mesh & Filter]
Skeleton_Data is just a simple IComponentData with just an animationTimer. (Maybe it should have references to the Body & Arms? But I can’t figure out how to do that, more on that later)
My conventional wisdom for how to build this would be to have one Skeleton_Animate_System, and in its OnUpdate, have an Entities.ForEach(Skeleton_Data) that…
- Looks at each skeleton_Data;
- Increases that skeleton_Data.animationTimer by deltaTime
- (Somehow) access skeleton_Data.body.translation, set translation derived from animationTimer
- (Somehow) access skeleton_Data.leftArm.rotation, set rotation derived from animationTimer
- (Somehow) access skeleton_Data.rightArm.rotation, set rotation derived from animationTimer
But this seems fundamentally contrary to the nature of ECS… because there’s no way for Skeleton_Data to store references to the Body translation & Arms’ rotations?
And as best I can tell, I can’t do a thing like Entities.ForEach(ref Skeleton_Data skeleton_Data, ref Translation body_Translation, ref Rotation armL_Rot, ref Rotation armR_Rot) => … because (1) you can’t have multiple of the same component (Rotation) in one ForEach, and (2), more importantly, can’t be combining components from different entities in one ForEach?
But maybe one of these assumptions is wrong?
Could someone please help me wrap my head around how this should be structured? What ComponentData and System(s) do I need for this incredibly simple project?