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