How to stop overlapping button "pressed" trigger

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Allan

I got a main scene where most of my background are populated with touch button nodes. Over the main scene I got a GUI canvas layer with fixed position texture buttons. My main scene can be panned and sometimes the texture_buttons overlaps the touch buttons on the background. When this happens, whenever I click the GUI texture button, the touch button also gets clicked, how can I stop this from happening?

Could you show some code? i think you could disable the button like in this post:

Ignore mouse on TouchScreenButton

Does it help?

p7f | 2018-11-16 12:09

By “overlap”, you mean they really end up drawing above the texture buttons above them?

Zylann | 2018-11-16 13:44

This is when I click the left most edge of the texture image above

Imgur: The magic of the Internet

and this is when I click somewhere in the middle where both overlaps

Imgur: The magic of the Internet

Allan | 2018-11-17 04:07

Sorry, there is no code yet, they are just literally
Node

TouchButton
CanvasLayer > TextureButton

Allan | 2018-11-17 04:10

Thanks for the link… I could use the “return” method if nothing else works, but in what Iam planning that would be very messy… Imagine the game Starcraft where the units are Touch button Nodes and your GUI and command cards are texture button on a canvas layer… that messy XD

Allan | 2018-11-17 04:19

Strange, that looks like a bug because in Godot UI, if you have two controls overlaid like this, your click event should always go to the topmost one and never reach the one behind (if gui_input or pressed signals are used of course).
Do you have a minimal reproduction project which shows the issue?

Zylann | 2018-11-17 14:37

Hi Zylann, the screenshots above are my minimal reproduction project, its really just a node2d as root then touchButton and canvasLayser as children and touchButton as child of canvasLayer… Give the buttons sprites of the same size and position them to overlap then connect their “pressed” signals to see who is triggering ( and they will trigger both ).
.
Regarding what you said, I test 2 textureButtons to overlap since they are inheriting from control class, and they do behave correctly! Only the top most textureButton gets clicked. It seems that said behavior is not applied to any other type of button that does not inherit from control class.

Allan | 2018-11-17 19:08

Ugh… that sucks. It’s strange to me that TouchButton is not a Control. Perhaps you could raise that problem in the issue tracker? (by providing your example projects so it’s easier to have a look)

Edit: actually, TouchScreenButton is not a Control on purpose… Shouldn't TouchScreenButton inherit from Control instead of Node2D? · Issue #15039 · godotengine/godot · GitHub, I’m quite confused about what the signals are for, now

Zylann | 2018-11-17 19:37

@Zylann, yeah… feeling hopeless about this one now… cant get a good solution even from r/godot and the facebook group… I would probably go the wild and rough way of funneling all func input(event) from top scene down instead of using the basic button pressed signals… THanks for help! :slight_smile:

Allan | 2018-11-17 21:16

You could try putting a Control under your button though, that could do the trick to stop input?

Zylann | 2018-11-17 22:05

I went ahead and ditched the standard pressed signals and use gui_input for the textureButton and input_event for the touchButton.

  • textureButton overlapping touchButton, textureButton gets input. OK
  • textureButton overlapping textureButton, top button gets input. OK
  • touchButton overlapping touchButton… both gets input. Not OK but I will not be having this scenario though :stuck_out_tongue:

Allan | 2018-11-18 02:50

Hi, perhaps it’s a good idea to post your solution as an answer and select it as best if you solved your issue, so other people facing the same problem see it’s solved!

p7f | 2018-12-02 15:08

:bust_in_silhouette: Reply From: Allan

I went ahead and ditched the standard pressed signals and use guiinput for the textureButton and inputevent for the touchButton.

  • textureButton overlapping touchButton, textureButton gets input. OK
  • textureButton overlapping textureButton, top button gets input. OK
  • touchButton overlapping touchButton… both gets input. Not OK but I will not be having this scenario though :stuck_out_tongue: