Hi all,
I have been trying for a few days to get an entity hierarchy happening just using code (no GameObjects). I have something like the following:
var topEntity = ecb.CreateEntity();
ecb.SetName(topEntity, "Parent");
ecb.AddComponent<LocalTransform>(topEntity);
ecb.SetComponent(topEntity, new LocalTransform { Position = new float3(1, 1, 1) });
ecb.AddComponent<LocalToWorld>(topEntity);
ecb.AddComponent<WorldTransform>(topEntity);
var childEntity = ecb.CreateEntity();
ecb.SetName(topEntity, "Child");
ecb.AddComponent<LocalTransform>(childEntity);
ecb.SetComponent(childEntity, new LocalTransform { Position = new float3(2, 2, 2) });
ecb.AddComponent<LocalToWorld>(childEntity);
ecb.AddComponent<WorldTransform>(childEntity);
ecb.AddComponent<ParentTransform>(childEntity);
ecb.AddComponent(childEntity, new Parent { Value = topEntity });
The entities appear in the hierarchy correctly. My understanding is that that LocalToWorld xyz show the actual location of the entity in the world. Parent above shows (1,1,1) as expected. Child I would expect to show (3,3,3) as it takes into account it’s own LocalTransform and the parent’s too. However when I run the code the Child has (1,1,1) as it’s LocalToWorld.
When I set up exactly the same as above using GameObjects it works as expected and the child has (3,3,3). Does anyone know why this is happening? There is very little documentation or example code regarding this setup which seems like it should be fairly straightforward.
Thanks!
Stu