Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

What is an efficient way of separating entities by type?

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

  1. inSight01


    Apr 18, 2017
    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


    Jan 21, 2018
    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.