Raycast registers one hit per collider

Hi there,

I have a very simple scene with just a box entity with a physics shape and a physics body set to kinematic.
I am trying to cast a ray through it and get the number of resulting hits. I expect to get two hits, one from “entering” the collider and one from “exiting” but only get one.

I am under the impression it should be working since this is a very basic setup. Am I missing something ?

Any help is much appreciated

            var CollisionWorld = SystemAPI.GetSingleton<PhysicsWorldSingleton>().CollisionWorld;

            var worldPosition = new int3(100, 200, 100);
            var rayDirection = new int3(0, -1, 0);

            var rayEnd = worldPosition + 1000 * rayDirection;

            RaycastInput input = new RaycastInput()
            {
                Start = worldPosition,
                End = rayEnd,
                Filter = new CollisionFilter
                {
                    BelongsTo = 1u << 0,
                    CollidesWith = 1u << 1,
                    GroupIndex = 0,
                },
            };

            var hits = new NativeList<Unity.Physics.RaycastHit>(Allocator.Temp);

            CollisionWorld.CastRay(input, ref hits);

            var hitCount = hits.Length;
            Debug.Log($"{hitCount}");

Seems like it actually is the intended behaviour. My bad.

A straightforward solution is to cast a new ray from every new intersection point until no intersection is found but this sounds quite inefficient for my use case (checking if a point is inside a group of meshes). Will explore other solutions.