So, I have this code:
public struct MovementComponent : IComponentData
{
public Entity Entity;
public float Speed;
public Vector3 Direction;
}
[BurstCompile]
public partial struct MovementSystem : ISystem
{
[BurstCompile]
public readonly void OnUpdate(ref SystemState state)
{
foreach (var (transform, movement) in SystemAPI.Query<RefRW<LocalTransform>, RefRO<MovementComponent>>())
{
transform.ValueRW = transform.ValueRO.Translate(movement.ValueRO.Speed * SystemAPI.Time.DeltaTime * movement.ValueRO.Direction.normalized);
}
}
}
I have entities that correspond to that query, and I can see their Position being updated in the inspector, as if they are moving, but they are not.
If I manually alter in the inspector the LocalTransform Position, or the LocalToWorld matrix, the objects move correctly, but somehow the automatic System updates to the LocalTransform are not being applied to the entities.
I noticed in the inspector that the LocalToWorld matrix is also not being automatically updated, only the Position of the LocalTransform is. Not sure if this is the expected behaviour, but like I said, changing this matrix manually also does make the entity move as expected.
I’ve also tried to force my System to run before the TransformSystemGroup, and after it, and nothing changes either way.
I’m sure it’s some simple detail that I’m missing. If anyone can help me with that it will be of great help to me.
If I had to guess, there is some other component on your entity that isn’t in the Unity Transforms namespace but has the attribute [WriteGroup(typeof(LocalToWorld))]. Unity Physics is a common culprit.
This is the full code of my “MovementAuthoring.cs”:
using Unity.Burst;
using Unity.Entities;
using Unity.Transforms;
using UnityEngine;
public class MovementAuthoring : MonoBehaviour
{
public float Speed = 10;
public Vector3 Direction = Vector3.zero;
}
public class MovementBaker : Baker<MovementAuthoring>
{
public override void Bake(MovementAuthoring authoring)
{
var entity = GetEntity(TransformUsageFlags.Dynamic);
AddComponent(entity, new MovementComponent
{
Entity = entity,
Speed = authoring.Speed,
Direction = authoring.Direction
});
}
}
public struct MovementComponent : IComponentData
{
public Entity Entity;
public float Speed;
public Vector3 Direction;
}
[BurstCompile]
public partial struct MovementSystem : ISystem
{
[BurstCompile]
public readonly void OnUpdate(ref SystemState state)
{
foreach (var (transform, movement) in SystemAPI.Query<RefRW<LocalTransform>, RefRO<MovementComponent>>())
{
transform.ValueRW = transform.ValueRO.Translate(movement.ValueRO.Speed * SystemAPI.Time.DeltaTime * movement.ValueRO.Direction.normalized);
}
}
}
I just created a normal 3D cube, added that component, and this is what it looks like:
There are no other files present. Brand new project. The Cube has 3 empty GameObject children that will serve as spawn points when I get this thing moving properly:

Pretty weird.
Is the subscene open and set to authoring data in your Preferences>Entities>Scene view mode? if you change it to runtime/and/or close the subscene do things appear correctly?
Scene view mode is “Runtime Data”. I can see the 3D cube in both Game AND Scene tabs, and if I manually change the value of the position in the inspector it moves properly in both tabs.
The problem is that my System is updating its position programatically and only in this case things do not move.
The image above shows the X position of the Cube being set incrementally through my System (currently at 165.7683) and as you can see, the cube is in the middle of the Game tab.
Note that the Local To World matrix has the value of 0 for the X of its last line.
Now, if I manually alter the Position of the Local Transform through the inspector, the result is like the image below, in which you can see that the Local To World matrix is correctly updated and the Cube goes from 0 (X axis) to 9.5 (X axis), which is the value I have set manually.
In fewer words: when the ISystem changes the Position of the Local Transform, the Local To World matrix does not get recalculated, so the object does not really move, but if I set some value for the Position of the Local Transform manually from the inspector, the Local To World matrix does get updated automatically and the object goes to its new position as expected.
For future reference, you can’t use readonly with the OnUpdate method, so I removed “readonly” from the following line:public readonly void OnUpdate(ref SystemState state)
No idea how it got there though, but it is what it is.