Button not working properly, when I click anywhere on the screen it is considered pressed

Godot Version

v4.4.1-stable

Question

I have an issue where the button that makes me select the difficulty is not working properly, because it apparently works when I click in the entire screen and not only where the button and animatedSprite is. I also have a question: when a node is child of a button is it supposed to send a signal pressed when clicked or only the button does that? (if you guys know a good yt channel or online website that covers godot it would be appreciated, I’m only using some channels for specific problems and the godot documentation for general stuff)

Why have you uploaded a zip file to github? How are we supposed to look at that or do you want us to just trust your zip file? I am not opening that!

Anyway, your button will recieve the click. It it is not handled, it will propagate up the tree until it is handled. Only the button should emit the clicked signal. If you are detecting clicks on a node that covers the entire screen, of course clicking anywhere will activate it.

There are literally hundreds of button examples out there. I did a search and found lots of very good looking tutorials on the subject. Some of them are from sites that offer complete godot courses and introductions for free. It would be worth investing a day or two running through lots of these as a learning exercise.

Oh I see sorry I should have just uploaded everything to the github without a zip right? I tried searching how to export and didn’t think there was a security fault with that, really sorry.
About the button, the button node is a child of the Control node (that covers the entire screen) but I didnt know how to fix that or if that really made a difference because i thought child buttons dont give the parents the “ability” to emit clicked signals. Anyway, I’ll try to do as you said and run some examples to see if get some insight

I must admit I have never put a child to a button, however I tested it by adding a sprite as a child of a button, and connected the button via the pressed signal to a parent so the sprite was bigger than the button.

As expected, only the button receives the click.

If you share a minimal version of your code that is causing the issue I am happy to take a look for you.

Script on control node:

extends Control

func _ready() -> void:
	pass

func _on_button_pressed():
	print("Hello, the button was clicked")

Button connected to parent script:

You can see the button under the sprite here, but clicking on the sprite area outside the button does not emit the pressed signal.

2 Likes

I see, I thought maybe child of buttons received the click but apparently not, and the issue is just that anywhere the button is receiving a click. I’ll try to share what I think is relevant but if you want to see something else just ask me


Script of difficulty button

Script of animated sprite of difficulty button:

box that toggles on and off when button is pressed

Is your diff button set to full screen. If so and your control node is set to full screen, your button will cover the entire screen. That is the only thing I can think of from what I can see.

Did you know there was a node called TextureBtn that allows you to add a texture like Sprite2D does? That might be a better option for you rather than using a child Sprite2D. With TextureBtn you can then add different sprites for hover, focussed, disabled etc.

Also I find it easier to first put your control node in its own canvas layer. Then to add margin layers to add different locations on the screen, a little like this:

Or with more sensible names:

Which looks like this on the viewport independent of the camera (Using GodotSVG for the button textures:

In this example the FullScreen is

And the margin containers are centered and bottom left. Both buttons work as expected.

Anyway, that is my best guess at what might be happening in your example.

Hope that helps in some way.

PS Something else that can help is in the output window under Misc you can see what node collected a click. Now in your case I think you know but it is a useful tool to bear in mind.

1 Like

My button without the Animated2D covering it is like this:


Also control is yes set at fullscreen, but the button probably isnt I search to see if there was an attribute named FullScreen for the button but I think you prob meant if the button occupied the entire screen. Also thanks for the tips about textButton, canvas layer and margin layers, im going to try to implement these changes and see if the problem persists. Maybe I’ll just create another project with your tips because in a way I’ve messed around so much the little I have in this project that I probably misconfigured something. Thanks a lot and apologies for the inconvenience earlier :slightly_smiling_face:

1 Like