mirror of
https://github.com/godotengine/godot-docs.git
synced 2026-01-05 22:09:56 +03:00
Add information on onready annotation to C# differences page (#4565)
This commit is contained in:
@@ -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<Label>("MyLabel");
|
||||
}
|
||||
|
||||
Singletons
|
||||
----------
|
||||
|
||||
|
||||
@@ -339,7 +339,8 @@ Here's the list of available annotations:
|
||||
+------------------------------+---------------------------------------------------------------------------------------------------+
|
||||
| ``@tool`` | Enable the `Tool mode`_. |
|
||||
+------------------------------+---------------------------------------------------------------------------------------------------+
|
||||
| ``@onready`` | Defer initialization of variable until the node is in the tree. See `Onready annotation`_. |
|
||||
| ``@onready`` | Defer initialization of variable until the node is in the tree. See |
|
||||
| | :ref:`doc_gdscript_onready_annotation`. |
|
||||
+------------------------------+---------------------------------------------------------------------------------------------------+
|
||||
| ``@icon(path)`` | Set the class icon to show in editor. To be used together with the ``class_name`` keyword. |
|
||||
+------------------------------+---------------------------------------------------------------------------------------------------+
|
||||
@@ -1726,8 +1727,10 @@ This also means that returning a signal from a function that isn't a coroutine w
|
||||
type-safety, because a function cannot say that returns an ``int`` but actually give a function state object
|
||||
during runtime.
|
||||
|
||||
Onready annotation
|
||||
~~~~~~~~~~~~~~~~~~
|
||||
.. _doc_gdscript_onready_annotation:
|
||||
|
||||
`@onready` annotation
|
||||
~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
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