Hi, I found that Component inherted type (non struct type) with EntityQueryDesc.Any does not work correctly.
Here is minimul reproducible code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Unity.Entities;
using System;
using Unity.Collections;
public class MyTestSystem : ComponentSystem
{
EntityQuery query;
protected override void OnCreateManager()
{
this.query = this.GetEntityQuery(new EntityQueryDesc()
{
All = Array.Empty<ComponentType>(),
Any = new ComponentType[]{ typeof(MyTypeA), typeof(MyTypeB)},
None = Array.Empty<ComponentType>(),
});
Entity e0 = this.EntityManager.CreateEntity();
this.EntityManager.AddComponentObject(e0, new MyTypeA());
Entity e1 = this.EntityManager.CreateEntity();
this.EntityManager.AddComponentObject(e1, new MyTypeB());
}
protected override void OnUpdate()
{
var typeA = this.GetArchetypeChunkComponentType<MyTypeA>();
var chunks = this.query.CreateArchetypeChunkArray(Allocator.TempJob);
foreach(ArchetypeChunk chunk in chunks)
{
var objects = chunk.GetComponentObjects(typeA, this.EntityManager);
// You can't use chunk.Has(typeA) because T is not IComponentData struct!
for(int i = 0; i < objects.Length; i++)
{
Debug.Log($"Length : {objects.Length}");
var obj = objects[i]; // This makes out of range exception
Debug.Log("TypeA");
}
}
chunks.Dispose();
}
}
public class MyTypeA : Component
{
}
public class MyTypeB : Component
{
}
This issue is already sent as case 1143042, but I wrote this post to gather more information for this issue.
Thanks.
(Tested on Entites 0.0.12-preview.31 + Unity 2019.2.0b1)