setting a collider to collide with other objects but not to be "detectable" by mouse being over it

the thing is, a physical object obstructing the way between camera and an object that needs to react to "OnMouseOver", I wish the said object to keep colliding with everything, as usual, but wasn't detectable by a ray cast from camera (Camera.screenPointToRay(input.mousePosition)) if I get my mouse over it. Any ideas?

This is the script for your GameObject:

gameObject.layer = LayerMask.NameToLayer("Ignore Raycast");

And you use Physics.Raycast like this:

Physics.Raycast(Vector3, Vector3, float, LayerMask.NameToLayer("Ignore Raycast"));