Is there a way to determine what Node is underneath the cursor at the given time without relying on signals of mouse_entered for each node?

You could try something like this if you use ray casting and don't mind adding 2D collision shapes to your nodes.

If the Nodes have straightforward, simple shapes, you could just do basic math to loop through each node and check its position against the mouse's position.

@TwistedTwigleg said: You could try something like this if you use ray casting and don't mind adding 2D collision shapes to your nodes.

Is there a way to do it without having to add collision shapes to all my nodes? I wanted to make a general purpose function for everything related to mouse click/dragging.

@SolarLune said: If the Nodes have straightforward, simple shapes, you could just do basic math to loop through each node and check its position against the mouse's position.

Wouldn't having a loop continuously running put a tax on performance?

Is there a way to do it without having to add collision shapes to all my nodes? I wanted to make a general purpose function for everything related to mouse click/dragging.

I'm not sure, but I don't think so, at least not with raycasts.

Maybe you could try something similar to the drag and drop demo? I'm not sure if it will be viable/useful, but maybe you can use control nodes as your parent nodes and then add whatever nodes you want to that?

@sprite-1 said: Wouldn't having a loop continuously running put a tax on performance?

Yes, but that's the nature of game development - it's a loop-based application. If you want to know when a Node is under the mouse, you have to determine that somehow. That means running a loop and checking for each Node's position, checking the physics state, using raycasts, etc. You're going to "loop" somehow, it's just a matter of how and when. I wouldn't really worry about performance unless it became a huge deal. If you're dealing with just a few objects, then it shouldn't be too much of a problem.

3 years later

Super old thread, but here is a snippet for anyone looking to check for hovering over a set of UI controls:

var mousePos = get_viewport().get_mouse_position()
for node in nodes:
	if node.get_global_rect().has_point(mousePos):
		#do the thing
		break
2 years later