Using ECS physics only for overlap checks. Alternatives?

So I’m at the point when I’m in need for more precise Entities overlapping checks.
But I don’t want to use physics simulations or even update colliders position since I’m trying to achieve very-high performance.

Best for me would be something like:

SphereCollider sph = new(position,radius);
BoxCollider bx = new(position, orientation,size);

isOverlapping = Physics.CheckOverlap.(sph,bx);

Is it possible with Unity.Physics ?
Are there any alternatives ?

All of the Unity.Physics Colliders have extension methods for cast and overlap checks.
I havent tried them but the code should look something like this.

var collider = new BoxCollider
{
    Geometry = new BoxGeometry
    {
        Center = default(float3),
        Orientation = default(quaternion),
        Size = default(float3)
    }
};

collider.CheckSphere(default(float3), default(float), default(CollisionFilter));

I just tried this code somewhere in random place of my application:

        var collider = new BoxCollider
        {
            Geometry = new BoxGeometry
            {
                Center = float3.zero,
                Orientation = quaternion.identity,
                Size = new float3(1,1,1),
            }
        };

        bool isColliding = collider.CheckSphere(new float3(0,0,0), 1,CollisionFilter.Default,QueryInteraction.Default);
        Debug.Log("Colliding: " + isColliding);

It returns false. Do I have to initialize physics in some special way ?

Do I have to initialize physics in some special way ?

Not quite. It seems that the collider has to be initialized.

var g = new Unity.Physics.SphereGeometry
{
    Center = default,
    Radius = 1
};
var s = new Unity.Physics.SphereCollider();
s.Initialize(g, CollisionFilter.Default, Unity.Physics.Material.Default);

Debug.Log(s.CheckSphere(default, 1, CollisionFilter.Default));

This returns true for me.
Keep in mind that i dont know if this is the intended way to do this.

2 Likes

Indeed it is working after initialization of collider.
Thank you.