Skip to content

Commit 644f066

Browse files
authored
Merge pull request #10938 from ProgrammerOnCoffee/update-gui-navigation-code-example
Add `call_deferred` to UI Navigation code example
2 parents b908bfc + a8ccd61 commit 644f066

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

tutorials/ui/gui_navigation.rst

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,22 +58,25 @@ have well-defined vertical or horizontal navigation flow.
5858
Necessary code
5959
--------------
6060

61-
For keyboard and controller navigation to work correctly, any node must be focused on
61+
For keyboard and controller navigation to work correctly, any node must be focused by
6262
using code when the scene starts. Without doing this, pressing buttons or keys won't
63-
do anything. Here is a basic example of setting initial focus with code:
63+
do anything.
64+
65+
You can use the :ref:`Control.grab_focus() <class_Control_method_grab_focus>` method
66+
to focus a control. Here is a basic example of setting initial focus with code:
6467

6568
.. tabs::
6669
.. code-tab:: gdscript GDScript
6770

6871
func _ready():
69-
$StartButton.grab_focus()
72+
$StartButton.grab_focus.call_deferred()
7073

7174
.. code-tab:: csharp
7275

7376
public override void _Ready()
7477
{
75-
GetNode<Button>("StartButton").GrabFocus();
78+
GetNode<Button>("StartButton").GrabFocus.CallDeferred();
7679
}
7780

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

0 commit comments

Comments
 (0)