Search Unity

What is an efficient way of separating entities by type?

Discussion in 'Physics for ECS' started by inSight01, Nov 18, 2021.

  1. inSight01

    inSight01

    Joined:
    Apr 18, 2017
    Posts:
    90
    I'm using a sphere cast to determine what entities are within range of a specific entity. But I'm curious to know if there is an efficient way of separating those entities by type.

    With Monobehaviour I could just do something like Collider.gameObject.tag or Collider.gameObject.layer. With entities I would assume I need to do something like EntityManager.HasComponent<T>(Entity) but I'm curious to know how expensive that call is.

    I could use multiple sphere casts (each used to collide with different entities) to simplify it but I would expect that to be very expensive.
     
  2. NT_Ninetails

    NT_Ninetails

    Joined:
    Jan 21, 2018
    Posts:
    196
    If you only want to collide with specific entities within the radius then you just need to utilize the ColisionFilter and use the CollisionWorld to perform the distance query. If you want to perform collision checks on a specific array/NativeList or entities then you would have to get a little more involved.