Whenever my mouse was over an interactable NPC/container, I wanted to change the mouse cursor to an interact icon. The caveat being I wanted the cursor to revert to the default whenever it was on top of a GUI because I don’t want this happening:
Let’s observe what my options are for determining if my mouse is over a GUI, and what that GUI is:
- Recurse through all GUI objects in the PlayerGui and manually check if the mouse is inside with position checks. This would not work well being run every time the mouse was moved or on heartbeat.
- Hook up every GUI ever made a descendant of the PlayerGui to MouseEnter/MouseLeave and use that to track the GUI object the cursor is over. That’s a lot of events, and pretty messy.
- Use something like quad trees to split the GUIs into manageable chunks that I can loop through on mouse move or heartbeat, which is arguably over-complicated for the purposes of something that you’d expect to be simple
While I was looking for something in the ROBLOX API to help me, I couldn’t really find anything. I did notice that whenever the mouse is over a GUI object with the active property enabled though, UIS processed = true. It looks like ROBLOX already keeps track of whether or not your mouse is over a GUI, and all that’s left is to expose that information. Right now I’ve made all GUIs’ lowest backgrounds active and added an additional check to my code to revert the cursor to default when processed = true, but being able to get the current GUI object the mouse was over, and having an event that fires when that object changes, would make accomplishing this a much, much cleaner process.