0 votes

I want to switch the focus of a button when I press a key so that the focus entered and exited
i made this and it does not work :

func _physics_process(delta):
    if Input.is_action_just_pressed("ui_accept"):
        $Button.grab_focus() = !$Button.grab_focus()
in Engine by (181 points)

1 Answer

0 votes

grab_focus() is just a function that sets the focus on the control it's called on. So, you can't set it to a boolean value as you're attempting to do.

To set the focus on $Button, you simply need to call $Button.grab_focus(). If you need to first see if $Button already has focus, you can call $Button.has_focus().

by (10,856 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.