Add information on onready annotation to C# differences page (#4565)

(cherry picked from commit 2a4dcc40d6)
This commit is contained in:
Matthew
2021-03-19 07:40:22 -04:00
committed by Rémi Verschelde
parent 5f37360f38
commit 226b44d3a7
2 changed files with 26 additions and 2 deletions

View File

@@ -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
----------

View File

@@ -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