Search Unity

What is the replacement for transform hierarchy?

Discussion in 'Entity Component System' started by kork, Mar 4, 2019.

  1. kork

    kork

    Joined:
    Jul 14, 2009
    Posts:
    280
    So in the latest release notes I read this:

    The ability to stack transforms and have "attached" objects follow the rotation and translation of its parent is very useful and we use this quite a bit in our game, so I wonder if we now have to implement this ourselves or if there is an alternative approach to this now.
     
    vitautart likes this.
  2. Soaryn

    Soaryn

    Joined:
    Apr 17, 2015
    Posts:
    328
    This made multiple depth sub orbit systems super handy, but now it rather more difficult/tedius to create :-(
     
  3. julian-moschuering

    julian-moschuering

    Joined:
    Apr 15, 2014
    Posts:
    529
    Didn't really use it yet but I think you just have to add the Parent component directly. I don't know what the comment '(No transform hierarchy)' means.
     
  4. vitautart

    vitautart

    Joined:
    May 3, 2018
    Posts:
    29
    My game depends heavy on this hierarchy. So second topic question.
     
  5. dzamani

    dzamani

    Joined:
    Feb 25, 2014
    Posts:
    122
    Take a look at Unity.Transforms.Tests.
    Everything you need is there, you can still have a hierarchy.
     
    vitautart likes this.
  6. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    1,555
    See Parent.cs

    Code (CSharp):
    1. using System;
    2. using Unity.Collections;
    3. using Unity.Entities;
    4. using Unity.Jobs;
    5.  
    6. namespace Unity.Transforms
    7. {
    8.     [Serializable]
    9.     [WriteGroup(typeof(LocalToWorld))]
    10.     public struct Parent : IComponentData
    11.     {
    12.         public Entity Value;
    13.     }
    14.  
    15.     [Serializable]
    16.     public struct PreviousParent : ISystemStateComponentData
    17.     {
    18.         public Entity Value;
    19.     }
    20.  
    21.     [Serializable]
    22.     [InternalBufferCapacity(8)]
    23.     [WriteGroup(typeof(ParentScaleInverse))]
    24.     public struct Child : ISystemStateBufferElementData
    25.     {
    26.         public Entity Value;
    27.     }
    28. }
    29.  
    ISystemStateBufferElementData is new. One system can mark multiple of same component per entity. Seems very suitable for hierarchy system. (1-many)Space for 8 childs allocated by default.

    Child and PreviousParent is probably a system state for the new EndFrameParentSystem. Now just setup Parent and those two will be added/managed. Should be WAY better than the old NativeMultiHashMap attach gymnastic bookkeeping that's hiding inside TransformSystem before now that we have a proper ISystemStateBufferElementData. (I had fought with so many bugs resulting from those mess)
     
    vitautart, kork, recursive and 2 others like this.
  7. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    Turns out the release notes are wrong... Sorry.

    So we actually have great parenting support in this release now. It's been rewritten.
    At runtime you just add a Parent component and assign the parent entity.


    In particular ConvertToEntity and SubScene workflow actually convert full hierarchies completely automatically now. Which makes the whole thing much more like traditional Unity.