Search Unity

Batching queries

Discussion in 'DOTS Physics' started by Tony_Max, Nov 5, 2019.

  1. Tony_Max

    Tony_Max

    Joined:
    Feb 7, 2017
    Posts:
    154
    Maybe i asking stupid question as always, so sorry

    In my project NPC must be able to see another NPC'c. To implement vision i use unity physics distance query. But different NPC'c belongs to different physics categories (layers). Some time NPC may need to "see" 0 layer for one algorithm, sometime 1 layer for another, sometime both.

    I see 2 possible approaches:
    1. Make just one physics query inside some "VisionSystem" and setting the collision filter from outside of that system depending on what NPC need to see. As a result i have raw Entity collection that i need to sort (cause as i say entities will be used for different algorithms) using ComponentDataFromEntity.Exists()
    2. Make physics query in every algorithm that need too "see" entities and have no centralized "VisionSystem".
    As far as I can judge from testing, centralized query is more perfomant. But the more important reason why i want to use 1st approach is i have no need to write boilerplates with injecting all physics instances that i need like collision world and so on. Also, all the code for vision is in one place.

    Is there a way to somehow sort result hits by physics categories? (using collectors?)
     
    Last edited: Nov 5, 2019
  2. Tony_Max

    Tony_Max

    Joined:
    Feb 7, 2017
    Posts:
    154
    I see now, that i can access CollisionFilter data through RigidBody.Collider*, but it requires unsafe code(
     
  3. steveeHavok

    steveeHavok

    Joined:
    Mar 19, 2019
    Posts:
    480
    Yeah, you can do this sort of thing to minimally make up unsafe sections
    Code (CSharp):
    1.             CollisionFilter filter = CollisionFilter.Default;
    2.             unsafe { filter = MyPhysicsColliderComponent.ColliderPtr->Filter; }
    3.             // use filter
    4.  
     
    Tony_Max likes this.
unityunity