Is there anyway to consume events so OnMouse events don't fire on objects with lower Z?

I have OnMouseAsButton defined on an object so that it fires when I click on it. However, I would like to block this behavior when another object is in front of it. I know you can eat the event with normal Event.current handling code, I was wondering if there is a way to do this with OnMouse events on Monobehavior.

You can do a raycast from the object that fires to it’s forward position, and if the ray collides with something then don’t allow your behavior to execute.