Note that the button is seen on the canvas, but the object with 2d collider is actually behind it.
The problem is that the button is not clickable!! even though from what i understand, raycasts from the camera should hit the button, before hitting that object and its colider.
you probably have already solved this, but out of curiosity I replicated your setup, and no, not getting the same result here…
Tested some settings, I guess you could have had negative settings in Canvas components “Order in Layer”… (something like -1000)
If this is the case, you’ll get clicks on 3D object with collider before you get a hit on a button on your world space canvas that is in front of 3D object.
I was bit too careless when reading your explanation.
Seems like the issues is having 2D box collider. If you were to use box collider instead, then the z-position of objWithCollider works like I described… and no need to change anything else I think.
I tested this with your scene.
At this point I have no idea how to setup your scene so that it works with 2D box collider.
OK. Quite interesting but actually now I think what you can do;
Use 3D box collider and Physic raycaster on your camera. This way you can just move 3D collider object behind your UI, at it works just fine.
If you want to keep your Physics 2D Raycaster and 2D box collider, go to your Graphic Raycaster in Canvas, set the Blocking objects enum; either make it 3D (that way 3D colliders only block UI) or make it 2D, this way 2D objects will block your UI sprites, but you can then set Blocking Mask below it, accordingly; objWithCollider on Layer custom would not be detected if blocking mask is set to Default only…
It’s because of the second thing I mentioned. EDIT: no idea if it makes any sense, but it seems to be working like this…
You’d have to set blocking objects or mask in your Graphic Raycaster.
Having 2D collider on plane object and 2D Physics Raycaster in camera will allow you to catch a click on plane object using EventSystem, but then again, EventSystem’s raycasts will will hit 3D object first (for some reason, I haven’t put effort into this enough to know why…).