Just wondering: is there already an easy way to disable a hierarchy of entities by just placing some component on the parent entity, or is iterating on all child entities and adding the Disabled component the only way?
EDIT: just found out about EntityManager.SetEnabled with a LinkedEntityGroup, but is there a job-compatible equivalent for EntityCommandBuffer?
For ECB specifically? No there is not. Depending on what your other requirements are and why you are asking, there might be other options. I’m actually working on creating specialized variants of ECB that use batch API on playback right now because ECBs are a bottleneck for me at scale.
public static class EcbExt
{
public static void SetEntityHierarchyEnabled(
this ref EntityCommandBuffer.ParallelWriter ecbp, int sortID, Entity entity, bool enabled,
BufferFromEntity<LinkedEntityGroup> linkedEntityGroupFromEntity)
{
if (linkedEntityGroupFromEntity.HasComponent(entity)) ecbp.SetEntityHierarchyEnabled(sortID, entity, enabled, linkedEntityGroupFromEntity[entity]);
else
{
if (enabled) ecbp.RemoveComponent<Disabled>(sortID, entity);
else ecbp.AddComponent<Disabled>(sortID, entity);
}
}
//for IJobChunk that you can test LinkedEntityGroup existence at chunk level;
public static void SetEntityHierarchyEnabled(
this ref EntityCommandBuffer.ParallelWriter ecbp, int sortID, Entity entity, bool enabled,
DynamicBuffer<LinkedEntityGroup> buffer)
{
if (enabled)
{
for (int i = 0, end = buffer.Length; i < end; i++)
ecbp.RemoveComponent<Disabled>(sortID, buffer[i].Value);
}
else
{
for (int i = 0, end = buffer.Length; i < end; i++)
ecbp.AddComponent<Disabled>(sortID, buffer[i].Value);
}
}
}