Search Unity

Proper way to set transforms so LocalToWorld is updated immediatly?

Discussion in 'Entity Component System' started by pakfront, Jun 15, 2019.

  1. pakfront

    pakfront

    Joined:
    Oct 6, 2010
    Posts:
    551
    I have system which uses the LocalToWorld of an object A that has moved on the same frame to set something on B.

    I find that if I set the Translate of A in a previous system, A renderer moves, but the LocalToWorld is not updated 'til the next frame.

    Unfortuately if I set LocalToWorld i this frame the renderer never moves.

    I uderstand why this is happening, LocalToWorld is rebuilt in the TransformSystemGroup, my workaround is I have to set both, but it's hacky. Note that it is done from the main thread in OnUpdate(), since I have only a few dozen entities of this type to set.

    Code (CSharp):
    1.                    EntityManager.SetComponentData(playerPointer.CurrentEntity,
    2.                         new LocalToWorld
    3.                         {
    4.                             Value = float4x4.Translate(playerPointer.WorldHitPosition)
    5.                         }
    6.                     );
    7.                     EntityManager.SetComponentData(playerPointer.CurrentEntity,
    8.                         new Translation { Value = playerPointer.WorldHitPosition }
    9.                     );
    Is there a better way to do this? I guess I could easily construct the matrix myself from Translation if I assume no parent xforms. Or just run after TransformSystemGroup, though that complicates some things.
     
    Last edited: Jun 15, 2019