EntityQuery inconsistency with subscenes

Im not sure if this is a bug but I’ve noticed that my EntityQuery.ToEntityArray(Allocator.TempJob); would produce a different order depending on if I have a subScene loaded or not.

For example, here i have PlanetMainScene loaded with auto load scene check
6715213--772033--Screen Shot 2021-01-11 at 11.08.14 PM.png
With the following to code

_profilerMarkerGetQueryVertices.Begin();
// Get all
_queryVertices.ResetFilter();
var vtxArray = _queryVertices.ToEntityArray(Allocator.TempJob);
var test = GetComponent<HexagonSphereVertexComponent>(vtxArray[11]).Index;
Debug.Log($"__ {test}");
_profilerMarkerGetQueryVertices.End();

… the output is 11 which is correctl

VS, here I have PlanetManScene unloaded with auto load scene check
6715213--772030--Screen Shot 2021-01-11 at 11.02.08 PM.png

… I get the value 14.

The index value is added in a IConvertGameObjectToEntity on an authoring script on a GO inside the PlanetMainScene subScene

int vertCount = (int) hexSphereContainer.vertexCount;
var vertEntities = new NativeArray<Entity>(vertCount, Allocator.Temp);
conversionSystem.CreateAdditionalEntity(this.gameObject, vertEntities);

for (int i = 0; i < vertCount; i++)
dstManager.AddComponentData(vertEntities[i], new HexagonSphereVertexComponent() {Index = i});

Visually you can see the problem

6715213--772045--Screen Shot 2021-01-11 at 11.19.36 PM.png 6715213--772048--Screen Shot 2021-01-11 at 11.19.20 PM.png

Is this a bug ? or should I never rely on an ToEntityArray order ?

Yes, you should not rely on the order in the ToEntityArray. Depending on your use case I would either only create one entity and store the array in a DynamicBuffer or give the single Entities an IComponentData with a “vertexArrayIndex” field.

1 Like

Indeed, never relay on query order.