diff --git a/EntitiesSamples/Assets/HelloCube/6. Reparenting/ReparentingSystem.cs b/EntitiesSamples/Assets/HelloCube/6. Reparenting/ReparentingSystem.cs index db933a271..dd369c11f 100644 --- a/EntitiesSamples/Assets/HelloCube/6. Reparenting/ReparentingSystem.cs +++ b/EntitiesSamples/Assets/HelloCube/6. Reparenting/ReparentingSystem.cs @@ -60,12 +60,16 @@ public void OnUpdate(ref SystemState state) // Attach all the small cubes to the rotator by adding a Parent component to the cubes. // (The next time TransformSystemGroup updates, it will update the Child buffer and transforms accordingly.) - foreach (var (transform, entity) in - SystemAPI.Query>() + var parentLocalToWorld = SystemAPI.GetComponent(rotatorEntity); + + foreach (var (localToWorld, entity) in + SystemAPI.Query>() .WithNone() .WithEntityAccess()) { ecb.AddComponent(entity, new Parent { Value = rotatorEntity }); + float3 localPosition = math.transform(math.inverse(parentLocalToWorld.Value), localToWorld.ValueRO.Position); + ecb.SetComponent(entity, new LocalTransform { Position = localPosition, Rotation = quaternion.identity, Scale = 0.5f }); } // Alternative solution instead of the above loop: