Search Unity

Question Alternative to Entities.WithStoreEntityQueryInField() for ISystem?

Discussion in 'Entity Component System' started by Sebioff, Oct 27, 2022.

  1. Sebioff

    Sebioff

    Joined:
    Dec 22, 2013
    Posts:
    218
    With the old Entities.ForEach-way of scheduling jobs it was possible to access the EntityQuery that's being used for the job through .WithStoreEntityQueryInField().

    Is there something comparable that works with ISystem?
    Looking into the generated code for an ISystem I can see the queries are all there, but I can't find a way to access them.
     
  2. WAYNGames

    WAYNGames

    Joined:
    Mar 16, 2019
    Posts:
    992
    Something like this ?
    Code (CSharp):
    1.     public void OnUpdate(ref SystemState state)
    2.     {
    3.         foreach (var (go,entity) in SystemAPI.Query<GameObjectRepresentation>().WithEntityAccess())
    4.         {
    5.             GameObject.Instantiate(go.Prefab);
    6.             Debug.Log($"Instanciating GameObject representation of entity {entity}");
    7.         }      
    8.     }
     
  3. Sebioff

    Sebioff

    Joined:
    Dec 22, 2013
    Posts:
    218
    Not quite, the point of WithStoreEntityQueryInField is that you don't have to manually write the EntityQuery yourself.
    Of course if you write a main thread foreach loop like in your example you have to do it, but when scheduling a job the query for it already gets generated automatically. The question is just if there is a way to access that query (like we had with Entities.ForEach) or not.
     
    Last edited: Oct 27, 2022
  4. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,684
    Nope. Idiomatic foreach API doesn't support that yet.
     
  5. Sebioff

    Sebioff

    Joined:
    Dec 22, 2013
    Posts:
    218
    Sorry, I'm not explaining it very well, but I'm not looking for something that has anything to do with idiomatic foreach.
    I need to access the EntityQuery that is generated when scheduling a job (i.e. IJobEntity), but I guess that's just not possible yet.
     
  6. davenirline

    davenirline

    Joined:
    Jul 7, 2010
    Posts:
    982
    How about building the query yourself? I'm not sure, though, if this is allowed in ISystem. This is pretty much our go to with normal class systems.
     
  7. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,684
    The same valid for IJobEntity - this API doesn't support that. Your best bet in that case (as described above), at least for now, is build your query and use if for schedule IJobEntity (for idiomatic foreach API you still can't use that as it's not a job)