pandemonium_engine_docs/usage/scripting/scene_unique_nodes.md

39 lines
909 B
Markdown
Raw Normal View History

2023-01-12 20:49:14 +01:00
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.
2023-01-12 20:16:00 +01:00
![](img/unique_name.png)
After checking this, the node will now have a percent symbol (**%**) next
to its name in the scene tree:
2023-01-12 20:16:00 +01:00
![](img/percent.png)
2023-01-12 19:43:03 +01:00
To use a unique node in a script, use the `%` symbol and the node's
name in the path for `get_node()`. For example:
2023-01-12 18:31:02 +01:00
gdscript GDScript
2023-01-12 18:31:02 +01:00
```
get_node("%RedButton").text = "Hello"
2023-01-12 18:31:02 +01:00
```