Multiple cameras and OnMouseDown

My gameplay uses OnMouseDown to handle clicking of in game objects. I recently added another camera that renders little sparkle particle effects over my HUD. This causes the OnMouseDown events to be lost in the main camera so you can’t click on anything in the game.

What should I do to fix this?

-Jon

1 Like

Put the other camera on the Ignore Raycast layer, maybe? (That does work for objects but I’m not quite sure what your setup is like.)

–Eric

Just tried it but it didn’t work, unfortunately. I’m all for ideas, though, so thanks :slight_smile:

The setup is a main camera with depth -1 that draws the game and HUD, which are GUITextures and stuff. Then I have another camera with depth 10 and clear flags of Depth Only, which only renders an Overlay layer I have setup that has some particle effects in it that place over the specific parts of the HUD.

There are colliders in the game with scripts attached that respond to OnMouseDown(). They don’t get the message when the overlay camera is enabled.

-Jon

1 Like

This same thing happened to me when I was trying to build a GUI out of stacked cameras. What happens when you give the two gui cameras the same depth?

Found the issue and fixed. Will be in 1.5.1.

It was a bug? Fixed? Great!

-Jon

Well maybe not a bug, lets call it a usability issue.

I found this thread now in 2021 and I’m having troubles with using OnMouseDown with stacked cameras.
A Google-search brought me here so I thought it’d be good if I write for anyone else who also ends up here.

OnMouseDown is not firing when I use two cameras in the scene, it works only if I have one enabled. Does anyone know how to fix it so OnMouseDown works with stacked cameras?

Edit: If anyone finds this thread in the future. I changed the priority of my base-camera to be higher (from 0 to 1), and that made OnMouseDown work for me. So if you have this problem in the future, maybe playing around with priorities will help you too!

19 Likes

OMG you are a freggin godsend! hours over several days looking for this simple fix.
I cant believe there aren’t more posts with this issue. Thanks for coming back to edit your comment.

In my case my base camera priority was set to -1. Read your comment then I set it to 0… worked like a charm.
I imbue upon thee my blessing of good fortune!

(blessing of good fortune: imbues the target with 6 months of programming with bugless code)

5 Likes