Entity transform values changing but entity isn't moving

Hi,

I’m having a wierd issue, I have a turret prefab which has a child “head”. My goal is to rotate the head (and only the head) towards a predetermined target. The problem is that if I go in the editor, I can see the head’s transform values changing and rotating towards the target, but I can’t actually see it in the scene. I know my code works, because the ray is always facing the target and if I turn the whole turret (instead of just the head), I can actually see it moving.

Here is my code :

[WorldSystemFilter(WorldSystemFilterFlags.ServerSimulation)]
[UpdateInGroup(typeof(CustomLateSimulationSystemGroup))]
public partial struct RotateTurretSystem : ISystem
{
    [BurstCompile]
    public void OnCreate(ref SystemState state)
    {
        state.RequireForUpdate<EnemyComponent>();
        using EntityQueryBuilder queryBuilder = new EntityQueryBuilder(Allocator.Temp)
        .WithAll<TurretComponent, Solidified>();
        state.RequireForUpdate(state.GetEntityQuery(queryBuilder));
    }

    [BurstCompile]
    public void OnUpdate(ref SystemState state)
    {
        foreach ((RefRO<TurretTarget> target, RefRW<LocalTransform> transform, RefRO<LocalToWorld> localToWorld, DynamicBuffer<Child> childrens)
        in SystemAPI.Query<RefRO<TurretTarget>, RefRW<LocalTransform>, RefRO<LocalToWorld>, DynamicBuffer<Child>>().WithAll<Solidified>())
        {
            if (!SystemAPI.Exists(target.ValueRO.Entity))
            {
                continue;
            }
            Entity head = childrens[0].Value;

            LocalToWorld targetTrans = SystemAPI.GetComponent<LocalToWorld>(target.ValueRO.Entity);
            RefRW<LocalTransform> local = SystemAPI.GetComponentRW<LocalTransform>(head);
            LocalToWorld trans = SystemAPI.GetComponent<LocalToWorld>(head);

            float3 direction = targetTrans.Position - trans.Position;
            direction.y = 0;
            direction = math.normalize(direction);
            direction = math.mul(math.inverse(trans.Rotation), direction);
            quaternion targetRotation = quaternion.LookRotationSafe(direction, math.up());
            local.ValueRW.Rotation = math.mul(targetRotation, local.ValueRO.Rotation);

            Debug.DrawRay(trans.Position, math.mul(trans.Rotation, direction) * 2, Color.blue);
        }
    }
}

Here is the turret’s hierachy :

Did you by chance mark the geometry as static?

If so then at load time the geometry “bakes off” the Transform and changing the Transform no longer modifies it the way it does at edit time.

No I don’t beleive I did, here is the head prefab :

1 Like

The only other thing I can think of would be an animation driving that one sub-object.

My go-to method for fixing stuff like this is to rip all the geometry off, put cubes in and run it.

That will quickly isolate if it is something about the prefab setup or something about the code.

Sorry, can’t help with the Entity stuff; haven’t really used it enough to have a sense of its problem surface beyond what I’ve picked up here.

1 Like

I fixed this by adding a “Ghost authoring Inspection Component” to my turret head and synching the transform values.

1 Like