You will find yourself referencing nodes from a scene in your code. In GDScript, that is usually achieved by using the dollar sign and the name of the object you want to reference (e.g. $MyNode
).
With SwiftGodot, you can achieve the same behavior by using:
- [[#the-scenetreemacro-macro|the
SceneTreeMacro
macro]] or - [[#the-bindnode-property-wrapper|the
BindNode
property wrapper]]1.
the SceneTreeMacro
macro
For more see @SceneTree macro
You typically use the path
parameter to specify the path to the node in your scene that you want to reference:
the BindNode
property wrapper
For more see @BindNode property wrapper
BindNode is an older version, but is not as convenient as using the @SceneTree macro.
In your class declaration, use the BindNode
property wrapper like this to reference the nodes that you created with the Godot Editor:
Footnotes
-
Use this if you are not using Macros ↩