scene_unique_nodes.rst 969 B

12345678910111213141516171819202122232425262728293031323334353637
  1. .. _doc_scene_unique_nodes:
  2. Scene Unique Nodes
  3. ==================
  4. Introduction
  5. ------------
  6. There are times in a project where a node needs to be called
  7. from a script. However, its position in the tree might change
  8. over time as adjustments are made to a scene, such as a
  9. button in a UI scene.
  10. In situations like this, a node can be turned into a scene
  11. unique node to avoid having to update a script every time
  12. its path is changed.
  13. Creating and using them
  14. -----------------------
  15. In the Scene tree dock, right-click on a node and select
  16. **Access as Scene Unique Name** in the context menu.
  17. .. image:: img/unique_name.png
  18. After checking this, the node will now have a percent symbol (**%**) next
  19. to its name in the scene tree:
  20. .. image:: img/percent.png
  21. To use a unique node in a script, use the ``%`` symbol and the node's
  22. name in the path for ``get_node()``. For example:
  23. .. tabs::
  24. .. code-tab:: gdscript GDScript
  25. get_node("%RedButton").text = "Hello"