Search Unity

Question Handling raycast "self-collision" with collisionfilters

Discussion in 'Physics for ECS' started by AverageCG, May 10, 2023.

  1. AverageCG

    AverageCG

    Joined:
    Nov 13, 2017
    Posts:
    19
    Hey, this might not be entirely a physics for ECS problem and it might be somewhat rudimentary but i've not experienced a similar problem in normal workflows mostly because i've not been working with lots of entities that all shoot rays to detect other entities of potentially the same archetype.

    Long story short after reading through a some definitions this is (i think) behaving the way i want it to but it seems a very roundabout way of achieving this. So i just wanted to ask whether this is the intended way of achieving this behaviour?

    Code (CSharp):
    1.  
    2. PhysicsCollider collider = state.EntityManager.GetComponentData<PhysicsCollider>(caster);
    3. var colliderFilter = collider.Value.Value.GetCollisionFilter();
    4. colliderFilter.GroupIndex = -caster.Index;
    5.  
    6. collider.Value.Value.SetCollisionFilter(colliderFilter);
    7. var input = new RaycastInput
    8.         {
    9.             Start = origin,
    10.             End = origin + direction * length,
    11.             Filter = CollisionFilter.Default
    12.         };
    13. input.Filter.GroupIndex = -caster.Index;
    I'm wondering whether there is something i'm still missing?
    Like this should be thread save since it doesn't matter what value exactly is stored in the groupindex as long as it isn't the exact same as the raycast collisionfilter value? Which it never should be unless entities ids change dynamically? Otherwise i could also just set the collider's collisionfilter.groupIndex the moment an entity is instantiated which might be better practice?

    I'm also not entirely sure what blobassets are yet and thought they would be completely static? Just because collider.value is of type BlobAssetReference<Unity.Physics.Collider>. I'm a little confused with ecs still

    Appreciate any pointers