Mouse click passing trough Color Rect

Godot Version

4.2.2

Question

I’m making a game that has a dialog box, and I made a big transparent color rect behind that you can click in order to close the dialog once it has finished, that works fine, however, the problem comes from the fact that if I have a button for example behind my mouse when I click on the color rect once to close it, it will close the dialog box but also trigger the button, as if It made a double click or the click passed through, maybe it has something to do with the input event handling order, however I searched for it and I don’t know how to change that, I should also say that the dialog box is a Control Node but the button is a node 2D with an area 2D because technically is part of the game and not GUI. I hope someone knows the reason for this, thank you!

Please show a screenshot

Otherwise to solve that, change the mouse_filter to pass or ignore, read this for more information.

Yes, of course, I’m sorry but I’ve been busy and I was not able to reply in a while.

So I have this text box that appears when the scene loads, once the text is fully displayed you can click anywere to close the window. I made the color rect on top slightly yellow so you can see it clearly.
You can click on the godot icon on the left to go to the second level 2.
The problem is that if you click directly on this godot icon, while the text box is still open it will carry you to the second level.


After closing the text window.

Finally here I have a link so you can download and check if you want, just take in mind that the project has other problems:

Please upload the project in google drive or here.

Here you go:

1 Like

I am not sure it is the correct way, but it will works:

  1. Add this code in the area input event function of Movement.gd:
    if DialogBox.just_gone: return
  2. Define a variable, like var just_gone = false in DialogBox.gd
  3. Write the following codes in the color rect gui input function of DialogBox.gd, after you called clear_label(), in the next line:
just_gone = true
await get_tree().create_timer(0.5).timeout
just_gone = false
1 Like

It works, I thought about doing something similar, using a timer to add some delay, but I thought maybe someone would come up with a more “elegant way” to do it, but I guess it is fine.
I changed the variable name of just_gone to stillvisible, to make it more clear for me.

I leave this here in case someone needs it

DialogBox script:
0.004 seems to be the minimum time for it to work

func _on_color_rect_gui_input(event):
		if Input.is_action_just_pressed("BothClicks") and label.visible_ratio >= 1:
			visible=false
			clean_label()
			
			stillvisible = true
			await get_tree().create_timer(0.1).timeout #0.004
			stillvisible = false

Movement script:

func _on_area_2d_input_event(viewport, event, shape_idx):

	if Input.is_action_just_pressed("BothClicks"):
		if DialogBox.stillvisible==true: return
		GameManager.change_room(nextscene, "normal")

Tell me if this is the way you did it, and thank you for your help!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.