#Getting Entity from Raycast to CompoundCollider

1 messages · Page 1 of 1 (latest)

tame hatch
#

Hello, I'm trying to execute a raycast and manipulate the entity that was hit, but the raycast always returns the parent entity because it's a compound collider
so I was trying to get the child entity that was hit using the ColliderKey, but even though the id is found, it returns Entity.Null
How can I return a proper entity here?

        private unsafe Entity GetHitEntity(RaycastHit hit)
        {
            var colliderKey = hit.ColliderKey;
            if (!EntityManager.HasComponent<PhysicsCollider>(hit.Entity))
                return hit.Entity;

            var collider = EntityManager.GetComponentData<PhysicsCollider>(hit.Entity);
            var ptr = collider.Value.GetUnsafePtr();
            if (ptr == null)
                return hit.Entity;
            ref var compoundCollider = ref UnsafeUtility.AsRef<CompoundCollider>(ptr);
            if (!compoundCollider.GetChild(ref colliderKey, out var childCollider))
                return hit.Entity;

            return childCollider.Entity;
        }

You can see the hierarchy in the screenshot, I want to detect if the raycast has hit the "GridVisual" object

tame hatch
#

ended up just flattening the hierarchy, unfortunately
way too much trouble to deal with

dapper blade
#

Are you on entities 1.3?

#

This was fixed in 1.3.0-pre.4

#
  • Prevent Entity.Null entries in the PhysicsColliderKeyEntityPair buffer of rigid body entities with compound colliders.
tame hatch
#

I'm on entities 1.2.3
I'll give it a try later then, thank you!

dapper blade
#

thats the entities changelog not physics