mirror of
https://github.com/godotengine/godot-docs.git
synced 2026-01-04 14:11:02 +03:00
Add information on onready annotation to C# differences page (#4565)
(cherry picked from commit 2a4dcc40d6)
This commit is contained in:
@@ -123,6 +123,28 @@ This attribute should be used on a `delegate`, whose name signature will be used
|
||||
|
||||
See also: :ref:`doc_c_sharp_signals`.
|
||||
|
||||
`onready` keyword
|
||||
-----------------
|
||||
|
||||
GDScript has the ability to defer the initialization of a member variable until the ready function
|
||||
is called with `onready` (cf. :ref:`doc_gdscript_onready_keyword`).
|
||||
For example:
|
||||
|
||||
.. code-block:: gdscript
|
||||
|
||||
onready var my_label = get_node("MyLabel")
|
||||
|
||||
However C# does not have this ability. To achieve the same effect you need to do this.
|
||||
|
||||
.. code-block:: csharp
|
||||
|
||||
private Label _myLabel;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_myLabel = GetNode<Label>("MyLabel");
|
||||
}
|
||||
|
||||
Singletons
|
||||
----------
|
||||
|
||||
|
||||
@@ -1647,8 +1647,10 @@ regardless of whether coroutines were used internally. Note that using
|
||||
``while`` would be redundant here as the ``completed`` signal is only emitted
|
||||
when the function didn't yield anymore.
|
||||
|
||||
Onready keyword
|
||||
~~~~~~~~~~~~~~~
|
||||
.. _doc_gdscript_onready_keyword:
|
||||
|
||||
`onready` keyword
|
||||
~~~~~~~~~~~~~~~~~
|
||||
|
||||
When using nodes, it's common to desire to keep references to parts
|
||||
of the scene in a variable. As scenes are only warranted to be
|
||||
|
||||
Reference in New Issue
Block a user