The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

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 (196 points)

2 Answers

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 (22,674 points)
0 votes

try this:

func _physics_process(delta):
    if Input.is_action_just_pressed("ui_accept"):
        if $Button.has_focus():
by (95 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 Frequently asked questions and 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 [email protected] with your username.