How to ignore signal checking if the button is not visible?

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

In order to disable touch button I set its visibility to false. It works perfectly except it returns error “not visible in tree”. I suspect it happens because it constantly has to check touch button signal to readily deliver as needed. And when it is invisible, code can’t check it and returns error. My question is, how do I make it check signal only when it’s visible?

what error are you getting?
which signal are you using?

As far as i know its not possible for an invisible node to receive touch events or broadcast such signals

Wakatta | 2021-02-04 20:21

Thank you for the reply!

Type: TouchScreenButton

Signal: _on_button_pressed()

Error (when invisible):
E 0:00:15.357 _input: Condition "!is_visible_in_tree()" is true. <C++ Source> scene/2d/touch_screen_button.cpp:201 @ _input() <Stack Trace> @ _process()

Again, what I suspect is that it is constantly under check, and when it doesn’t see it (if it is invisible) it throws error message. But the game doesn’t crash or anything, it works fine. But debugger shows hundreds of these errors (probably every frame?)

Suleymanov | 2021-02-04 20:42

I see the infamous TouchScreenButton rears it head again. Not sure what that button is supposed to do but i’ll recommend you use any other button under Control > BaseButton instead. To directly answer your question do the check for if is_inside_tree(): or if visible(): inside your signal call though i suspect something entirely different is happening here.

Wakatta | 2021-02-04 23:15

Your suspicions are probably true. It may have something to do with the stuff it has to do when signal is out, and not the signal itself. Maybe I over-complicated stuff. To understand it I’ll create a new project to test it out from the ground up and let you know. Thank you bud!

Suleymanov | 2021-02-05 07:22