This thread nicely fits an issue I ran into today: I’m trying to set the local rotation, via Rotation. But for some reason, that rotation isn’t kept unless I write via commandBuffer.SetComponent(…). The strange thing about this is that it works fine when I set the position of root entities (that have no parent) via Translation. But when I try to set the Rotation of an entity that does have a parent, it only works via the command buffer.
So, I have one system that essentially does this (and it does exactly what I want - these entities have no parents):
[UpdateInGroup(typeof(SimulationSystemGroup))]
[UpdateBefore(typeof(StepPhysicsWorld))]
[UpdateAfter(typeof(GameplayEventsActivitySystem))]
public class GameplayEventsMovementSystem : SystemBase {
protected override void OnUpdate() {
Entities
.ForEach((Entity entity,
int entityInQueryIndex,
ref Translation translation,
in Movement movement) => {
translation.Value = math.lerp(movement.PositionStart, movement.PositionEnd, timeFrac);
})
.WithName("MoveJob")
.ScheduleParallel();
}
}
And another one that doesn’t work when I write it this way (the rotations are not stored in Rotation or LocalToParent):
[UpdateInGroup(typeof(SimulationSystemGroup))]
[UpdateBefore(typeof(StepPhysicsWorld))]
[UpdateAfter(typeof(GameplayEventsActivitySystem))]
public class GameplayEventsApplyDirectionSystem : SystemBase {
protected override void OnUpdate() {
Entities
.WithAll<ApplyDirection>()
.ForEach((
Entity entity,
int entityInQueryIndex,
ref Rotation rotation,
in GameplayEventRoot ger
) => {
if (HasComponent<Directionality>(ger.Parent)) {
Directionality direction = GetComponent<Directionality>(ger.Parent);
rotation.Value = direction.Rotation;
}
})
.WithName("GameplayEventApplyDirectionJob")
.ScheduleParallel();
}
}
When I replace the line rotation.Value = direction.Rotation; with:
commandBuffer.SetComponent(entityInQueryIndex, entity, new Rotation() {
Value = direction.Rotation
});
I get exactly what I want (obviously, there’s also some boiler plate code then, which creates the command buffer). Does anyone have an idea why rotation.Value = direction.Rotation; might not work?
Another system overwriting this can be ruled out because in my actual code, I only do this once and it still works fine with the command buffer version - and it still doesn’t work when I write it every frame with the other version.