Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at id.unity.com during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.


    Read our full announcement for more information and let us know if you have any questions.

Question ECS - Setting localToWorld doesn't update child entities positions.

Discussion in 'Entity Component System' started by Yoconn, Feb 2, 2023.

  1. Yoconn

    Yoconn

    Joined:
    Jan 12, 2015
    Posts:
    10
    How are you supposed to move a parent entity and have the child entities 'follow'?

    I've tried googling this but... I might be using the wrong terminology or something.

    I'm working off the Boids example and this is what I'm currently doing.

    Code (CSharp):
    1.                
    2. localToWorld.Value = float4x4.TRS(
    3.     new float3(localToWorld.Position + (nextHeading * MoveDistance)),
    4.     quaternion.LookRotationSafe(nextHeading, math.up()),
    5.     new float3(1.0f, 1.0f, 1.0f));
    6.  
     
  2. TheOtherMonarch

    TheOtherMonarch

    Joined:
    Jul 28, 2012
    Posts:
    901
    Yoconn and Anthiese like this.
  3. Yoconn

    Yoconn

    Joined:
    Jan 12, 2015
    Posts:
    10
  4. TheOtherMonarch

    TheOtherMonarch

    Joined:
    Jul 28, 2012
    Posts:
    901
    Yes
     
  5. Tudor

    Tudor

    Joined:
    Sep 27, 2012
    Posts:
    150
    But how do you change the non-uniform scale if you shouldn't use localToWorld?

    ah, like this: https://forum.unity.com/threads/how-to-scale-a-entity-in-a-non-uniform-way.1411515/
    magical hidden by default component, got it.

    (the docs are very unclear what it is, "you may use a PostTransformScale (float3x3). This will be applied in the following manner: LocalToWorld = WorldTransform.ToMatrix() * PostTransformScale", had to search around a lot for usage and context; it didn't even mention it's a component or part of a component)
     
    Last edited: Mar 26, 2023
  6. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,701
    layker90524 likes this.
  7. muntes

    muntes

    Joined:
    Nov 24, 2021
    Posts:
    24
    Hi,

    Do you have any idea how to scale a child of a parent entity in a non-uniform way?

    entityManager.AddComponentData(productEntity, new LocalTransform { Position = localMatrix.position, Rotation = localMatrix.rotation});
    entityManager.SetComponentData(productEntity, new PostTransformMatrix {Value = float4x4.Scale(localMatrix.scale) });

    For example this generates a 0,0,0 LocalToWorld.
     
  8. Spy-Master

    Spy-Master

    Joined:
    Aug 4, 2022
    Posts:
    908
    LocalTransform.Scale isn’t set in that code, so it will be 0.