0 votes


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.

in Engine by (15 points)

1 Answer

+2 votes
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:

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.

by (10,584 points)
selected by
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 Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.