How do I access a variable from my code in Godot's editor?

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:

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.

• I am curious. Does Godot have a feature like Unity to set the accepted ranges, like export var may_var = 5 #[0, 10]? – Drew Feb 19 '18 at 19:52
• @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... – TARDIS Maker Feb 19 '18 at 21:05
• It is possible to add a range for the editor: export(type, min, max, step) – BadgerBadger Apr 25 '18 at 4:33