Exporting variables to the editor
We have always defined variables within code and every time we wanted to change them, we had to change the code too. But in Godot, it is straightforward to expose variables to the editor so that we can change them without even opening the code editor. This is extremely useful when you want to test things out and tweak variables on the fly. An exported variable pops up in the Inspector view of that node, just like the transformation and text properties we saw in the Manipulating nodes in the editor section.
Important note
An exported variable is also useful for people who don’t know how to code, such as level designers, but still want to change the behavior of specific nodes.
To export a variable to the editor, we can use the @export
annotation. Let’s change the line where we define the health
variable, like so:
@export var health: int = 10
Make sure you save the script. Go to the 2D editor using the button at the top of...