I seem to have a problem of “compatibility” between these two features in Unity.
First, I had implemented a Physics Raycast in one of my scripts, in order to determine where on my map the pointer was pointing. The script was something like this:
private void ThrowRaycast()
{
RaycastHit raycastHit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out raycastHit, 100))
{
PointerPosition = GridSystem.GridPosition(raycastHit.point, MapPresenter.mapDisplayed.mapID, false);
}
}
Everything worked fine, I used this raycast to determine in real time the position of my pointer on the map.
Then recently I added a Physics Raycaster component to my camera, so I could use a IClickHandler interface on one of my objects. The problem is that now my Physics Raycast doesn’t seem to work. If I deactivate the Physics Raycaster the Physics.Raycast works fine again; and when I reactivate it, it doesn’t work well again.
I’ve been trying to check the documentation, but I couldn’t find much information on this. What is the link between these to things? Should I replace my Physics.Raycast with something else, or is there a way to fix it?
Maybe it was a problem of layer. Maybe I needed to setup the layers of the objects I wanted to click.
I also remember I had several cameras at the same time at some point, it might have been the cause of my issue.
I haven’t touched my code above which is still exactly the same, and the camera still has a Raycaster attached to it.
Just had this happen. Would love to know what’s going on. My UI is all in the UI layer. My scene objects are in the Default layer. My PhysicsRaycaster mask is set to Default. My camera mask includes Default and other stuff (but not some things I am hiding).
As the OP writes, the moment I added a PhysicsRaycaster to my main Camera (I have a second camera, but can’t see how that would matter), my use of Physics.Raycast() always returns false. If I disable the PhysicsRaycaster component, even while the game is running, my regular raycasts work again.
Similar to the OP, I wanted to try to use IPointerClickHandler to respond to double clicks on objects in my scene, so I didn’t have to write a custom double-click detector. And maybe I will convert all my other input handling to use the same event system. But I wanted to do it a piece at a time, not all at once.