0 votes

Hello,

I have a Node2D as root with the following nodes as children:

  • TextureButton A
  • TextureButton B (positioned in the center of the screen)
  • Area2D (with Sprite and CollisionShape2D as children)

If TextureButton A gets pressed, the Area2D is set to visible and gets drawn on top of the TextureButton B. But if I click on the center of the Area2D the TextureButton B below still gets triggered. I want to prevent this and just can't figure out how to do this properly.

I have a script attached to the root node of the scene and could easily disable this button, if the TextureButton B gets pressed, but I believe there is a better method.

I would be very grateful, if anyone could give me a hint.

Thank you very much.

asked Jun 14 in Engine by kdominik (15 points)

1 Answer

+1 vote
Best answer

but I believe there is a better method.

Not really. I recommend you read up on how InputEvents work in Godot. If you want to grab and consume the InputEvent before it reaches your Buttons, you would need to do the following:

func _input(event):
    if event is InputEventMouseButton and event.pressed:
        get_tree().set_input_as_handled()

That works because the _input-method receives an event before the GUI elements. However, the above code does not check where the mouse click actually happened and if your Area2D-node was visible or not. While ensuring those things is possible, I wouldn't say it's "better" than simply deactivating the button here.

answered Jun 14 by njamster (8,986 points)
selected Jun 15 by kdominik
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.