Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice
  2. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  3. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Children entities not moving with parent entity

Discussion in 'Project Tiny' started by dallin_unity, Dec 30, 2020.

  1. dallin_unity

    dallin_unity

    Joined:
    Dec 18, 2019
    Posts:
    40
    Hi guys, I have made a simple character customization feature for my project
    https://www.fastfps.com/demo/virtualmarket/VirtualMarket.html

    But after that, the children entities (male, male_body, ...) of the main character entity is not moving with its parent (character)
    upload_2020-12-30_18-16-11.png

    Am I missing anything or did I do anything wrong? please help.
     
  2. AbdulAlgharbi

    AbdulAlgharbi

    Unity Technologies

    Joined:
    Jul 27, 2018
    Posts:
    319
    can you share a repro project or the script that makes the character move?
     
  3. dallin_unity

    dallin_unity

    Joined:
    Dec 18, 2019
    Posts:
    40
    Hi, thanks for replying
    The player move to where the footstep move, here is the code that translate the footstep

    Code (CSharp):
    1. Entities.WithAll<FootStepTag>().ForEach(( ref Translation translation) =>
    2. {
    3.  
    4.     if (pointerEntity != Entity.Null && HasComponent<GroundTag>(pointerEntity))
    5.     {
    6.      
    7.         translation.Value = new float3(pointerRaycastHit.Position.x, translation.Value.y, pointerRaycastHit.Position.z);
    8.     }
    9.  
    10. }).WithoutBurst().Run();
    Then this is the code to update a movable component data

    Code (CSharp):
    1.  
    2. Entity playerEntity = GetSingletonEntity<PlayerTag>();
    3.  
    4. Entity footstepEntity = GetSingletonEntity<FootStepTag>();
    5.  
    6. var footstepTranslation = GetComponent<Translation>(footstepEntity);
    7.  
    8. var playerTranslation = GetComponent<Translation>(playerEntity);
    9.  
    10. float distance = math.distance(footstepTranslation.Value, playerTranslation.Value);
    11.  
    12. float3 direction = math.normalize(footstepTranslation.Value - playerTranslation.Value);
    13.  
    14. Moveable moveable = new Moveable();
    15. moveable.moveForce = 30;
    16.  
    17. if (distance < 0.4f)
    18. {
    19.  
    20.     moveable.moveDirection = new float3(0, 0, 0);
    21.  
    22. }
    23. else
    24. {
    25.  
    26.     moveable.moveDirection = new float3(direction.x, 0, direction.z);
    27. }
    28.  
    29. EntityManager.SetComponentData(playerEntity, moveable);
    Then this is the code to move the player

    Code (CSharp):
    1.  
    2. Entities.WithAll<PlayerTag>().ForEach((ref Moveable moveable,
    3.         ref Rotation rotation, ref LocalToWorld localToWorld, ref Translation translation) =>
    4.     {
    5.      
    6.         if (math.abs(moveable.moveDirection.x) > 0.1f || math.abs(moveable.moveDirection.z) > 0.1f)
    7.         {
    8.             // Look where you're going
    9.             rotation.Value = quaternion.LookRotation(moveable.moveDirection, localToWorld.Up);
    10.  
    11.             translation.Value += moveable.moveDirection * 3 * deltaTime;
    12.          
    13.         }
    14.      
    15.     }).WithoutBurst().Run();
    Sorry the code is not yet optimized.
     
  4. AbdulAlgharbi

    AbdulAlgharbi

    Unity Technologies

    Joined:
    Jul 27, 2018
    Posts:
    319
    looks ok to me
    I don't see any issues why the player is not moving
    maybe check that deltaTime is not zero
    also, make sure moveable.moveDirection is getting the values from the footstep
     
    dallin_unity likes this.
  5. dallin_unity

    dallin_unity

    Joined:
    Dec 18, 2019
    Posts:
    40
    Thanks, actually the code is working, but only the parent entity is moving, the one with PlayerTag, I don't know why the children entities is not moving with the parent, especially after I disable (EntityManager.SetEnabled)
    and enable them (enable and disable clothes in character customization)
     
  6. GilCat

    GilCat

    Joined:
    Sep 21, 2013
    Posts:
    676
    Make sure the system that handles Translation and Rotation is updated before Transform group
     
    AbdulAlgharbi likes this.
  7. dallin_unity

    dallin_unity

    Joined:
    Dec 18, 2019
    Posts:
    40
    What do you mean? the translation and rotation is update every frame (call in OnUpdate function)
    I have changed some codes, this happens if I try to move the parent entity to somewhere far (using EntityManager.SetComponentData on the entity translation) if I move them closer, the clothes will follow, but still it disappear when the player walking and reappear sometime, please check the new build
    https://www.fastfps.com/demo/virtualmarket/VirtualMarket.html

    Thanks you guys so much for your time.
     
  8. djsell

    djsell

    Joined:
    Aug 29, 2013
    Posts:
    77
    I played with it a bit. The base skin seems to be fine. If I select clothes, the clothes will sometimes disappear. I wonder if how you dynamically add them isn't adding something that the skinned mesh setup requires.
     
    dallin_unity likes this.
  9. dallin_unity

    dallin_unity

    Joined:
    Dec 18, 2019
    Posts:
    40
    I tried to enable and disable clothes entity (EntityManager.SetEnabled)

    upload_2021-1-7_11-23-17.png

    upload_2021-1-7_11-23-31.png

    Thanks so much for your time.
     
  10. GilCat

    GilCat

    Joined:
    Sep 21, 2013
    Posts:
    676
    The way transform system works in DOTS is that Translation, Rotation, Scale (and others) components values will be copied to LocalToWorld in systems belonging to the Transform System Group, if you set the values of such components after the Transform Group you will miss the chance to update LocalToWorld (used by the renderer) on the same frame and possible causing problems. I advise you to add
    Code (CSharp):
    1. [UpdateBefore(typeof(TransformSystemGroup))]
    on the system where you change those values.

    You can also read more about transform system here.
     
    dallin_unity likes this.
  11. dallin_unity

    dallin_unity

    Joined:
    Dec 18, 2019
    Posts:
    40
    Thanks, I tried but didn't work, I think this have something to do with enable and disable the entity, if I put clothes on the character without enable or disable it (in character customization menu) then it works fine
     
    GilCat likes this.