I’m testing out the different ways of querying entities and am learning about some of the patterns that current ECS users are using. I’m attracted to the idea of using tag components with no data to better group my entities. I’m also interested in the new ForEach lambda, but when I use it to make a query that includes tag components, I see runtime exceptions. Tags work all right in IJobForEach.
I understand that ForEach generates high-efficiency boilerplate, and that this may be what precludes using a tag in one. However, I wanted to double check to see whether:
-
There is a convenient way to use tags with ForEach that I’m missing, since I’m just starting to learn ECS conventions.
-
If not, whether the ForEach codegen eventually will accommodate zero-length components.
Here is the ForEach that throws exceptions:
public class TagSystem_ForEach : JobComponentSystem {
protected override JobHandle OnUpdate( JobHandle inputDependencies ) {
float deltaTime = Time.DeltaTime;
var jobHandle = Entities.ForEach( (
ref Translation translation,
in Player playerTag
) => {
translation.Value = new float3( translation.Value.x + deltaTime, translation.Value.y, translation.Value.z );
}
).Schedule( inputDependencies );
return jobHandle;
}
}
Here is the IJobForEach that doesn’t.
public class TagSystem : JobComponentSystem {
[BurstCompile]
struct TagSystemJob : IJobForEach<Translation, Player> {
public float deltaTime;
public void Execute( ref Translation translation, [ReadOnly] ref Player playerTag ) {
translation.Value = new float3( translation.Value.x + deltaTime, translation.Value.y, translation.Value.z );
}
}
protected override JobHandle OnUpdate( JobHandle inputDependencies ) {
var job = new TagSystemJob { deltaTime = Time.DeltaTime };
return job.Schedule( this, inputDependencies );
}
}
The exception is:
System.ArgumentException: ArchetypeChunk.GetNativeArray<{0}> cannot be called on zero-sized IComponentData