I am trying out the new unity ECS 1.0 and I am trying to add a component to a child entity.
How can I add components to child entities? and how can I access different components in child entities?
I am trying out the new unity ECS 1.0 and I am trying to add a component to a child entity.
How can I add components to child entities? and how can I access different components in child entities?
How can I add components to child entities?
EntityManager.AddComponentData( child , new MyComponent{ Value = 1234 } );
how can I access different components in child entities?
if( EntityManager.HasBuffer<Child>(parentEntity) )
foreach( Entity child in EntityManager.GetBuffer<Child>(parentEntity) )
{
Debug.Log($"{child} has MyComponent: {EntityManager.HasComponent<MyComponent>(child)}");
}
or, sometimes Child
components are replaced with LinkedEntityGroup
:
if( EntityManager.HasBuffer<LinkedEntityGroup>(parentEntity) )
foreach( Entity relative in EntityManager.GetBuffer<LinkedEntityGroup>(parentEntity) )
{
Debug.Log($"{relative} has MyComponent: {EntityManager.HasComponent<MyComponent>(relative)}");
}