File tree Expand file tree Collapse file tree 1 file changed +8
-5
lines changed Expand file tree Collapse file tree 1 file changed +8
-5
lines changed Original file line number Diff line number Diff line change @@ -58,22 +58,25 @@ have well-defined vertical or horizontal navigation flow.
58
58
Necessary code
59
59
--------------
60
60
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
62
62
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:
64
67
65
68
.. tabs ::
66
69
.. code-tab :: gdscript GDScript
67
70
68
71
func _ready():
69
- $StartButton.grab_focus()
72
+ $StartButton.grab_focus.call_deferred ()
70
73
71
74
.. code-tab :: csharp
72
75
73
76
public override void _Ready()
74
77
{
75
- GetNode<Button>("StartButton").GrabFocus();
78
+ GetNode<Button>("StartButton").GrabFocus.CallDeferred ();
76
79
}
77
80
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
79
82
or a controller can be used to navigate between it and other UI elements.
You can’t perform that action at this time.
0 commit comments