Gowydot This is strange... can you tell me how did you know that it didn't work? If it was an error, then could you write down what the error is? Is it the same case with TextureButton? My guess is that when Control node is ready, the TextureButton2 is not there yet as its child (in other words, TextureButton2 cannot be found). But, when the code line is in func _ready()
of TextureButton2.gd, it doesn't matter, because it will be executed whenever TextureButton2 node is ready (i.e. added as a child).
I also wanted to note that grab_focus()
is different from has_focus()
. Here is a quote from "https://docs.godotengine.org/en/stable/classes/class_control.html#class-control-property-focus-mode":
#QUOTE START
"void grab_focus ( )
Steal the focus from another control and become the focused control (see focus_mode).
void grab_click_focus ( )
Creates an InputEventMouseButton that attempts to click the control. If the event is received, the control acquires focus.
func _process(delta):
grab_click_focus() #when clicking another Control node, this node will be clicked instead
bool has_focus ( ) const
Returns true if this is the current focused control. See focus_mode."
#QUOTE END