Search Unity

ECS Parenting an entity during runtime

Discussion in 'Entity Component System' started by pmzshvlsbqyodeolhd, Jun 10, 2020.

  1. pmzshvlsbqyodeolhd

    pmzshvlsbqyodeolhd

    Joined:
    Jun 10, 2020
    Posts:
    2
    I’ve got two entities in a scene, a sphere and a cube. I want to set the sphere to be a child of the cube after a variable condition is met.

    I’ve had a read around and I can’t seem to find an explanation or example on how you would do this during runtime via a system or similar.

    Wondering if anyone can help explain the process/provide an example of how this is done?
     
  2. Orimay

    Orimay

    Joined:
    Nov 16, 2012
    Posts:
    304
    Try adding Parent component to the sphere and point to the cube entity:
    Code (CSharp):
    1. EntityManager.AddComponentData(eSphere, new Parent() { Value = eCube });