mirror of
https://github.com/godotengine/godot-docs.git
synced 2026-01-04 14:11:02 +03:00
Document scene unique nodes (#5831)
* Document scene unique nodes
* Apply suggestions from code review
Co-authored-by: Hugo Locurcio <hugo.locurcio@hugo.pro>
(cherry picked from commit fd545c7a3e)
This commit is contained in:
BIN
tutorials/scripting/img/percent.png
Normal file
BIN
tutorials/scripting/img/percent.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.9 KiB |
BIN
tutorials/scripting/img/unique_name.png
Normal file
BIN
tutorials/scripting/img/unique_name.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.5 KiB |
@@ -51,3 +51,4 @@ below will help you make the most of Godot.
|
||||
resources
|
||||
singletons_autoload
|
||||
scene_tree
|
||||
scene_unique_nodes
|
||||
|
||||
36
tutorials/scripting/scene_unique_nodes.rst
Normal file
36
tutorials/scripting/scene_unique_nodes.rst
Normal file
@@ -0,0 +1,36 @@
|
||||
.. _doc_scene_unique_nodes:
|
||||
|
||||
Scene Unique Nodes
|
||||
==================
|
||||
|
||||
Introduction
|
||||
------------
|
||||
|
||||
There are times in a project where a node needs to be called
|
||||
from a script. However, its position in the tree might change
|
||||
over time as adjustments are made to a scene, such as a
|
||||
button in a UI scene.
|
||||
|
||||
In situations like this, a node can be turned into a scene
|
||||
unique node to avoid having to update a script every time
|
||||
its path is changed.
|
||||
|
||||
Creating and using them
|
||||
-----------------------
|
||||
|
||||
In the Scene tree dock, right-click on a node and select
|
||||
**Access as Scene Unique Name** in the context menu.
|
||||
|
||||
.. image:: img/unique_name.png
|
||||
|
||||
After checking this, the node will now have a percent symbol (**%**) next
|
||||
to its name in the scene tree:
|
||||
|
||||
.. image:: img/percent.png
|
||||
|
||||
To use a unique node in a script, use the ``%`` symbol and the node's
|
||||
name in the path for ``get_node()``. For example:
|
||||
|
||||
.. tabs::
|
||||
.. code-tab:: gdscript GDScript
|
||||
get_node("%RedButton").text = "Hello"
|
||||
Reference in New Issue
Block a user