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

How to write this particular EntityQuery?

Discussion in 'Entity Component System' started by duzbot, Feb 19, 2020.

  1. duzbot

    duzbot

    Joined:
    Aug 31, 2017
    Posts:
    17
    How would you write an EntityQueryDesc to include the Entity instance of the current entity?
    Like how you can do with the lambda Entities.ForEach(Entity entity)
     
  2. BackgroundMover

    BackgroundMover

    Joined:
    May 9, 2015
    Posts:
    209
    You can call .ToEntityArray() on an EntityQuery to get an array of all the entities that match the query, if I'm understanding you
     
    duzbot likes this.
  3. felipin

    felipin

    Joined:
    Nov 18, 2015
    Posts:
    49
    EntityQuery doesn't require to define if it should contain or not entity array, because entity array is Intrinsic to every chunk and also is read-only, there's no reason to declare whether or not a entity query is gonna access the entity array, so if you wanna access it only do what you should do, e.g., for a Entities.ForEach lambda you should define a parameter for Entity (I'm not sure about it, but I think it should always be the first parameter), for Chunk iteration you should use ArchetypeChunk.GetNativeArray(ArchetypeChunkEntityType) and for IJobForEach[_*] you should use the IJobForeEachWithEntity[_*] version.
     
    duzbot likes this.
  4. duzbot

    duzbot

    Joined:
    Aug 31, 2017
    Posts:
    17
    Thanks, both comments were helpful
    Also - how do I get the nativeThreadIndex value in an IJobForEach?
    like with lambda .ForEach, you can pass the named parameter nativeThreadIndex

    I feel like I am making some misunderstandings between the way we use .ForEach and IJobForEach, please bear with me because i am slowly connecting the... DOTS :)
     
    Last edited: Feb 20, 2020
  5. BrendonSmuts

    BrendonSmuts

    Joined:
    Jun 12, 2017
    Posts:
    86
    There is an attribute you can use to mark an integer field in your job structure, [NativeSetThreadIndex] that DOTS will then inject the thread index into.
     
    duzbot likes this.