Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Parent entities to other entities

Discussion in 'Entity Component System' started by LukePammant, Jan 20, 2019.

  1. LukePammant

    LukePammant

    Joined:
    Mar 10, 2015
    Posts:
    50
    Is there any way to parent an entity to another entity so that it inherits the Rotation, Position, Scale from the parent?


    Currently the only way I can think to do it is via a Hybrid solution of creating a new GameObject, adding a GameObjectEntity component to it and adding all my components to that.
     
  2. RecursiveEclipse

    RecursiveEclipse

    Joined:
    Sep 6, 2018
    Posts:
    298
    When you parent to an entity you do inherit position, rotation, and scale in world space. Rotation, Position, and Scale are assumed to already be local to parent when you parent them, it doesn't alter them like unity editor does with gameobjects automatically.

    Right now, I'll parent entities and don't need to touch the position or rotation because they snap to where the parent is in world space, so locally, as the child, position and rotation are 0.

    I'm not sure if you know how to attach already, it is a bit strange, so here it is:

    Create a new entity with an Attach component(Attach, not AttachComponent), then set Parent and Child Fields of the Attach as your parent/child entities. TransformSystem picks up the entity with Attach, parents them, then deletes the attach entity.
     
    Last edited: Jan 21, 2019
    rsodre, JesOb and LukePammant like this.
  3. rsodre

    rsodre

    Joined:
    May 9, 2012
    Posts:
    229
    This Attach component, does it still exists? I can't find it in Unity.Transforms.
    Or was it replaced for something else?
     
  4. TRS6123

    TRS6123

    Joined:
    May 16, 2015
    Posts:
    246
    Parenting was replaced. You now just attach Parent and LocalToParent components to the child entity, setting the Value field of the Parent to the desired parent entity.
     
    Radivarig likes this.