In Godot, I have a node with a variable that I often need to tweak for balancing purposes. It would be a lot easier to manage if I could modify it inside the editor instead of the code.

How would I go about doing this?


This can be done with the export keyword.

export var my_var = 5

# No default value
export(int) var my_int

The result of this code in the editor is this:

enter image description here

It is possible to use pretty much any type used in the engine as can be seen in the documentation. This means that you could set a scene resource to be instanced from the editor instead of hard-coding it in.

  • \$\begingroup\$ I am curious. Does Godot have a feature like Unity to set the accepted ranges, like export var may_var = 5 #[0, 10]? \$\endgroup\$
    – Drew
    Feb 19 '18 at 19:52
  • \$\begingroup\$ @Drew I took a quick look at the documentation and it doesn't seem like this is currently possible. It definitely seems like a useful feature though. I wonder if anyone would be interested implementing it... \$\endgroup\$ Feb 19 '18 at 21:05
  • 6
    \$\begingroup\$ It is possible to add a range for the editor: export(type, min, max, step) \$\endgroup\$ Apr 25 '18 at 4:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.