LocalTransform component doesn`t corresponding authoring Transform

Hi!
I’m new at UnityECS. I’m trying repeat some tutorials (simple cube rotating in this case), but I faced an unknowing problem: changing params of LocalTransform on it’s entity doesn’t change params of common Transform of this cube in Editor, which means cube doesn`t even move
Currently I’m using Unity 2022.3.12f1 and Entities 1.0.16
Tell me pls how to fix this strange issue

Editor window for clear example:

Component&System scripts:

public class RotateSpeed : MonoBehaviour
{
    public float Value;

    private class RotateSpeedBaker : Baker<RotateSpeed>
    {
        public override void Bake(RotateSpeed authoring)
        {
            Entity entity = GetEntity(TransformUsageFlags.Dynamic);
            AddComponent(entity, new RotateSpeedData
            {
                Value = authoring.Value
            });
        }
    }
}
public struct RotateSpeedData : IComponentData
{
    public float Value;
}
public partial struct RotatingCubeSystem : ISystem
{
    public void OnUpdate(ref SystemState state)
    {
        foreach (var (transform, speed) in SystemAPI.Query<RefRW<LocalTransform>, RefRO<RotateSpeedData>>())
        {
            transform.ValueRW = transform.ValueRO.RotateY(speed.ValueRO.Value * SystemAPI.Time.DeltaTime);
        }
    }
}

1 Answer

1

This Inspector is showing Runtime values with clear numerical signs of rotation happening. So your system works.

Cube is not rotating at the moment because open (open for authoring) subscene causes editor to switch to rendering authoring GameObjects instead of their runtime Entity. So remember to close this subscene (untick that toggle in Hierarchy window) to see a rotating cube.

checkbox


The other Inspector window is in Authoring mode. Authoring values are initial values (think of them as values you put in a prefab).

Thanks for your answer, but for me this is still unclear ;/ I understood the difference between Runtime and Authoring inspectors and I thought that exactly initial values of this cube's transform change it's rotation on scene. Is that wrong? You told me close this subscene in Hierarchy window, but when I'll close it there won't be cube on scene at all :sweat_smile: Sorry, but can you explain it a little bit wider for me?

I had this specific checkbox in mind there. Unchecking it will end authoring mode for this subscene and triggers GameObject->Entity baking process. Technically, you can go into authoring subscenes while in Play mode, but consider this being outside of standard workflow.

These initial values, sourced from this GameObject, change values on corresponding Entity - you got this part right. This happens in one direction, GO->Entity, only. What you miss, in my estimation, is that subscene in Authoring mode (i.e. open) makes the Editor render it's content Authoring GameObjects and hide corresponding entities (ones that will be rotated by RotatingCubeSystem). RotatingCubeSystem is not interested in authoring GameObjects.