• Godot HelpGUI
  • How can I block mouse events when mouse on Control node?

I want create the context menu in my game, which appears right on the game field, but if I just create it and place where I need, game field will be proccess mouse events under the context menu and when player doing something in this menu, game field reacting. In other words, I want to create focus on specific GUI element.

for example: script:

extends Sprite

func _process(delta):
	if Input.is_action_just_pressed("mouse_left"):
		if get_rect().has_point(get_local_mouse_position()):
			modulate = Color(1, 0, 0)

I want to sprite colored red only when I click outside texture rect:

u can apply this only to certain other nodes like 'panel' and block back items

@Zelta I don't quite understand what you mean, but this option don't doing what I need

Ok, I found info about it. In sprite script should be used _unhandled_input.

The way that I sometimes do features like this, I will use the signals that control nodes have (mouse_entered and mouse_exited). You can connect these signals to the script and use a boolean to track if the mouse is in side the rect or not, along with behavior for when it enters and exits. If you want mouse events to not be processed when the mouse is inside the rect, you could say "only process this event IF mouseInRect is false"

ups sorry... normally it works, but looks the input rule over the other things or something.

i use this system usually for the pause and escape menus, for 'block' the back/main scene.

if u just use a texture button insted a sprite it works. but maybe is not what u need in this case. The @ElephantInTheRoom method looks pretty good, have u tried?

@Zelta I've not tried this method, becouse _unhandled_input function works good. I've not seen problems with this yet. Still I've not created context menu, but game pause menu over the game field works pretty good and mouse setting stop-pass-ignore allows to control passing of the mouse events.

2 years later