From 2a4dcc40d600d367be633ad1e6888a32b8abfe45 Mon Sep 17 00:00:00 2001 From: Matthew Date: Fri, 19 Mar 2021 07:40:22 -0400 Subject: [PATCH] Add information on onready annotation to C# differences page (#4565) --- .../scripting/c_sharp/c_sharp_differences.rst | 22 +++++++++++++++++++ .../scripting/gdscript/gdscript_basics.rst | 9 +++++--- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/tutorials/scripting/c_sharp/c_sharp_differences.rst b/tutorials/scripting/c_sharp/c_sharp_differences.rst index 3df8b3c5f..72f3ebcb1 100644 --- a/tutorials/scripting/c_sharp/c_sharp_differences.rst +++ b/tutorials/scripting/c_sharp/c_sharp_differences.rst @@ -128,6 +128,28 @@ This attribute should be used on a `delegate`, whose name signature will be used See also: :ref:`doc_c_sharp_signals`. +`@onready` annotation +--------------------- + +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_annotation`). +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