MouseOverAny: Multiple Objects Underneath?

All,

I’ve run into an issue with MouseOverAny. I’ve got some terrain and I have a few meshes for UI menu buttons over the terrain. Objects are added to the terrain by a third object that handles mouse clicks (depending on its state). All of this works fine, but when I click on a UI button, it also adds an object underneath it (both objects are getting the event).

If necessary, I’ll refactor things so I use MouseOver (vs MouseOverAny), but that breaks the “tool widget” sort of layout I have now.

I was looking for a way to get a list of hitObjects from the MouseOverAny event so I could determine if there were multiple objects under the mouse, but it only appears to return a single object. Is that somewhere in the API that I’ve missed?

TIA!

For those interested in my solution:

There is no way to get a list of all objects under the mouse within one call. I solved this problem by breaking the UI out into an overlay scene that holds just UI. I then took out MouseOverAny and replaced it with MouseOver. This avoided the whole ‘multiple objects under mouse’ problem.

Mouse Over is nothing more than a specialized Ray Sensor. It sends a ray from the near clipping plane to the far clipping plane where the line under the cursor crosses these planes.

As usual the ray stops with the first detected face.

If you want more faces, you can measure with additional rays via Python, performing a chain of rays.

In general I recommend to place a GUI in an overlay anyway. This keeps it separate from the game and avoids conflicts as you discovered.

mouse over vs mouse over any:

Mouse over is the object concentric approach (the object itself manages the event).
Mouse over any is an “Manager” approach (a separate object manages the event).

Each mouse over and each mouse over any send a ray. This means more sensors = more processor consumption. As ray/mouse over/mouse over any are heavy sensors (in terms of performance) it is advised to limit the number of such sensors. From performance perspective it is better to use one mouse over any rather than multiple mouse over. I do not know if future versions of the BGE will share the same ray making it faster.