EntityQueryBuilder.ForEach未使用两个ComponentData和一个BufferElementData进行编译

问题描述 投票:0回答:1

当我尝试编写以下代码时

Entities.WithAll<SomeComponentData, SomeComponentData2, SomeBufferElementData>()
        .ForEach((Entity entity,  ref SomeComponentData componentData, ref SomeComponentData2 componentData2, DynamicBuffer<SomeBufferElementData> buffer) => {

});

我收到以下错误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'.

当我只使用一个ComponentData和一个BufferElementData时,它编译良好,即以下工作:

Entities.WithAll<SomeComponentData, SomeBufferElementData>()
        .ForEach((Entity entity,  ref SomeComponentData componentData, DynamicBuffer<SomeBufferElementData> buffer) => {

});

我看了ForEach代码,它是生成的代码,其中包含许多组件和动态缓冲区的排列,但是这不是!在不支持ComponentData和BufferElementData的排列的情况下会发生什么?

unity3d unity-ecs
1个回答
0
投票

原来支持此排列,但我必须将DynamicBuffer放在首位。那是:

Entities.WithAll<SomeBufferElementData, SomeComponentData, SomeComponentData2>()
        .ForEach((Entity entity,  DynamicBuffer<SomeBufferElementData> buffer, ref SomeComponentData componentData, ref SomeComponentData2 componentData2) => {

});

我通过查看IJobForEachWithEntity_XXX接口发现了这一点。我发现有一个IJobForEachWithEntity_EBCC接口,提示我缓冲区必须在组件之前。

希望这可以节省某人几个小时的时间!

© www.soinside.com 2019 - 2024. All rights reserved.