Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Bug GetSingleton() failed: found no chunk that matches the provided filter.

Discussion in 'Entity Component System' started by Oneiros90, Jul 14, 2023.

  1. Oneiros90

    Oneiros90

    Joined:
    Apr 29, 2014
    Posts:
    77
    Hello, I have a very straightforward system:

    Code (CSharp):
    1. public partial struct MySystem : ISystem
    2. {
    3.     private EntityQuery _activePlayersQuery;
    4.  
    5.     public void OnCreate(ref SystemState state)
    6.     {
    7.         _activePlayersQuery = SystemAPI.QueryBuilder().WithAll<ActivePlayerTag, Transform>().Build();
    8.         state.RequireForUpdate(_activePlayersQuery);
    9.     }
    10.    
    11.     public void OnUpdate(ref SystemState state)
    12.     {
    13.         var activePlayerPosition = _activePlayersQuery.GetSingleton<Transform>().position;
    14.         ...
    15.     }
    16. }
    Where
    ActivePlayerTag
    is an empty
    IComponentData
    and
    Transform
    is the UnityEngine transform.
    I've been reported a weird case in a build run where the
    GetSingleton()
    method generated this error:

    Code (CSharp):
    1. Exception: InvalidOperationException: GetSingleton() failed: found no chunk that matches the provided filter.
    2.  
    3. Unity.Entities.EntityQueryImpl.GetSingletonChunk (Unity.Entities.TypeIndex typeIndex, System.Int32& outIndexInArchetype, Unity.Entities.Chunk*& outChunk) (at <00000000000000000000000000000000>:0)
    4. Unity.Entities.EntityQueryManagedComponentExtensions.GetSingleton[T] (Unity.Entities.EntityQuery query) (at <00000000000000000000000000000000>:0)
    Any Idea on what's going on?
     
  2. Wobbers

    Wobbers

    Joined:
    Dec 31, 2017
    Posts:
    55
    Did you manually add the transform via
    EntityManager.AddComponentObject
    ?
    Otherwise, you probably want to replace
    Transform
    with
    LocalTransform
    , since Transform is not an ECS-Component and you will usually not find it attached to any entity (Transform on GameObject will be baked to LocalTransform in resulting Entity).

    Not sure why your system will even run though. If you just use "normal" baked entities, this query will not match anything. Since your query seems to contain something, maybe you can try

    state.EntityManager.GetComponentObject<Transform>(_activePlayersQuery.GetSingletonEntity())
    instead and see if it gets you something.