I'm using the Unity Entity Component System. When I try to write the following code:
Entities.WithAll<SomeComponentData, SomeComponentData2, SomeBufferElementData>()
.ForEach((Entity entity, ref SomeComponentData componentData, ref SomeComponentData2 componentData2, DynamicBuffer<SomeBufferElementData> buffer) => {
});
I get the following error error CS0315: The type 'Unity.Entities.Entity' cannot be used as type parameter 'T0' in the generic type or method 'EntityQueryBuilder.ForEach<T0>(EntityQueryBuilder.F_D<T0>)'. There is no boxing conversion from 'Unity.Entities.Entity' to 'Unity.Entities.IComponentData'.
It compiled fine when I was just using one ComponentData and one BufferElementData i.e. the following worked:
Entities.WithAll<SomeComponentData, SomeBufferElementData>()
.ForEach((Entity entity, ref SomeComponentData componentData, DynamicBuffer<SomeBufferElementData> buffer) => {
});
I had a look at the ForEach code, which is generated code with lots of permutations of components and dynamicbuffers, but I couldn't find this one. (see answer - I just wasn't looking hard enough!) What happens in this situation where the permutation of ComponentData and BufferElementData is not supported?
Turns out this permutation was supported but I had to put the DynamicBuffer first. That is:
I found this out by looking at the
IJobForEachWithEntity_XXX
interfaces. I found that there was anIJobForEachWithEntity_EBCC
interface, which tipped me off to the fact that the buffer had to go before the components.Hope this will save someone a few hours of their time!