Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Component inherited type with EntityQueryDesc.Any doesn't work correctly

Discussion in 'Entity Component System' started by Kichang-Kim, May 13, 2019.

  1. Kichang-Kim

    Kichang-Kim

    Joined:
    Oct 19, 2010
    Posts:
    1,008
    Hi, I found that Component inherted type (non struct type) with EntityQueryDesc.Any does not work correctly.

    Here is minimul reproducible code:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using Unity.Entities;
    5. using System;
    6. using Unity.Collections;
    7.  
    8. public class MyTestSystem : ComponentSystem
    9. {
    10.     EntityQuery query;
    11.  
    12.     protected override void OnCreateManager()
    13.     {
    14.         this.query = this.GetEntityQuery(new EntityQueryDesc()
    15.         {
    16.             All = Array.Empty<ComponentType>(),
    17.             Any = new ComponentType[]{ typeof(MyTypeA), typeof(MyTypeB)},
    18.             None = Array.Empty<ComponentType>(),
    19.         });
    20.  
    21.         Entity e0 = this.EntityManager.CreateEntity();
    22.         this.EntityManager.AddComponentObject(e0, new MyTypeA());
    23.  
    24.         Entity e1 = this.EntityManager.CreateEntity();
    25.         this.EntityManager.AddComponentObject(e1, new MyTypeB());
    26.     }
    27.  
    28.     protected override void OnUpdate()
    29.     {
    30.         var typeA = this.GetArchetypeChunkComponentType<MyTypeA>();
    31.         var chunks = this.query.CreateArchetypeChunkArray(Allocator.TempJob);
    32.  
    33.         foreach(ArchetypeChunk chunk in chunks)
    34.         {
    35.             var objects = chunk.GetComponentObjects(typeA, this.EntityManager);
    36.  
    37.             // You can't use chunk.Has(typeA) because T is not IComponentData struct!
    38.          
    39.             for(int i = 0; i < objects.Length; i++)
    40.             {
    41.                 Debug.Log($"Length : {objects.Length}");
    42.                 var obj = objects[i]; // This makes out of range exception
    43.                 Debug.Log("TypeA");
    44.             }
    45.         }
    46.  
    47.         chunks.Dispose();
    48.     }
    49. }
    50.  
    51. public class MyTypeA : Component
    52. {
    53. }
    54.  
    55. public class MyTypeB : Component
    56. {
    57. }
    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)
     
    yomuhyeonseop likes this.
  2. RoughSpaghetti3211

    RoughSpaghetti3211

    Joined:
    Aug 11, 2015
    Posts:
    1,697
    YEP looks like its always returning length 0 for me
     
  3. Kichang-Kim

    Kichang-Kim

    Joined:
    Oct 19, 2010
    Posts:
    1,008
    Thanks for testing this issue. I received the response from Unity:
    So we can't use "Any" filter for that. (But seems that "All" filter works correctly.)