• Godot Help
  • GD4: How to check if a button is in focused from the parent? (grab/has_focus())

I can not use grab/has_focus() from Control on its TextureButtons.

Tree:
Control
-TextureButton
-TextureButton2

#This works
TextureButton2.gd

func ready():
	grab_focus()

#This doesn't work, also with has_focus()
Control.gd

func ready():
	$TextureBotton2.grab_focus()

Right now I'm testing if I can use it to delete the active button. Any recommendation?
Thank you

    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

    Thanks again. Your reply made me realized I have to put them on _process() for it to work.😅 stupid me.
    I will try work it on the inventory code.