Skip to content

Add call_deferred to UI Navigation code example #10938

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions tutorials/ui/gui_navigation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,25 @@ have well-defined vertical or horizontal navigation flow.
Necessary code
--------------

For keyboard and controller navigation to work correctly, any node must be focused on
For keyboard and controller navigation to work correctly, any node must be focused by
using code when the scene starts. Without doing this, pressing buttons or keys won't
do anything. Here is a basic example of setting initial focus with code:
do anything.

You can use the :ref:`Control.grab_focus() <class_Control_method_grab_focus>` method
to focus a control. Here is a basic example of setting initial focus with code:

.. tabs::
.. code-tab:: gdscript GDScript

func _ready():
$StartButton.grab_focus()
$StartButton.grab_focus.call_deferred()

.. code-tab:: csharp

public override void _Ready()
{
GetNode<Button>("StartButton").GrabFocus();
GetNode<Button>("StartButton").GrabFocus.CallDeferred();
}

Now when the scene starts the "Start Button" node will be focused, and the keyboard
Now when the scene starts, the "Start Button" node will be focused, and the keyboard
or a controller can be used to navigate between it and other UI elements.