Menu

Godot @export: Export Variables to the Inspector

@export shows a variable in Godot's Inspector so you can tune it without editing code. Export numbers with ranges, enums, files, nodes, resources and arrays, group them, and avoid the default value trap.

This page includes runnable editors. Edit, run, and see output instantly.

@export shows a member variable in the Inspector, the panel where you edit a node's properties. You can then tune values per node, in the editor, without touching the code:

extends CharacterBody2D

@export var speed := 200.0
@export var jump_height := 64.0
@export var max_health: int = 5

Two enemies with this script can now have different speeds, set right in their scenes. An exported variable is still a normal variable, with the script's value as its default:

Hero moves at 200.0 with 3 lives

An exported variable needs a type or a starting value, so the Inspector knows which field to draw. @export var target with neither is an error: Cannot use simple "@export" annotation with variable without type or initializer, since type can't be inferred.

Exporting with Hints

Annotations after @export_ pick a better editor field:

@export_range(0, 100, 5) var volume := 80                     # a slider in steps of 5
@export_range(0.0, 1.0) var crit_chance := 0.1
@export_range(0, 500, 1, "or_greater") var damage := 10       # may go past 500
@export_enum("Warrior", "Mage", "Rogue") var job: int = 0     # a drop-down
@export_multiline var description := ""                     # a big text box
@export_file("*.json") var level_file := ""                   # a file picker
@export_dir var save_folder := ""                             # a folder picker
@export_color_no_alpha var tint := Color.WHITE                # a color without alpha
@export_flags("Fire", "Ice", "Poison") var resist := 0        # check boxes as bit flags

An exported variable typed with one of your enums also shows a drop-down: @export var team: Team = Team.RED.

Exporting Nodes, Scenes and Resources

A node type lets you pick another node of the scene in the Inspector:

@export var target: Node2D
@export var health_bar: ProgressBar
@export var bullet_scene: PackedScene
@export var item: ItemData          # your own Resource class
@export var icon: Texture2D

Node exports are set before _ready(), so they are ready to use there. Exporting a node is often better than $Path or @onready with a path, because it keeps working when you move or rename the node.

Exporting Arrays and Dictionaries

@export var spawn_points: Array[Vector2] = []
@export var waves: Array[PackedScene] = []
@export var drop_chances: Dictionary[String, float] = {}

The Inspector shows a list where you add, remove and reorder items. Type the array, as above, so each item gets the right field. See typed arrays.

Groups and Categories

Long scripts get tidy sections in the Inspector:

@export_category("Enemy")

@export_group("Movement")
@export var speed := 120.0
@export var acceleration := 600.0

@export_group("Combat")
@export var damage := 1
@export var attack_range := 32.0

@export_group("")      # end the group
@export var debug_draw := false

@export_subgroup("Name") nests one level deeper inside a group.

The Default Value Trap

Once you change an exported value in the Inspector, the scene saves your value. Changing the default in the script afterwards does not affect that node. This is the most common "my code change does nothing" moment in Godot. The Inspector shows a revert arrow beside any value that differs from the script's default; click it to go back to the default.

The order is:

  1. The object is created with the script's defaults.
  2. Godot applies the values saved in the scene, calling setters if there are any.
  3. _ready() runs, and sees the final values.

Exports That Update in the Editor

By default your script only runs in the game. Add @tool as the first line to run it in the editor too, so an exported color can change a sprite while you drag the color picker. Guard game-only code with if Engine.is_editor_hint(): return.

@export or Not

Export what a designer would tune: speeds, damage, colors, which scene to spawn, which node to follow. Keep internal state, such as the current velocity or a timer's progress, as plain variables, so the Inspector shows only what matters.

Frequently Asked Questions

How do I export a variable in Godot 4?

Put @export before var: @export var speed := 200.0. Save the script, select the node, and the variable appears in the Inspector. Godot 3's export var keyword was replaced by the @export annotation.

Why does changing the default value in code not change my node?

Once you edit an exported value in the Inspector, the scene stores that value, and it wins over the default in the script. Click the revert arrow next to the property in the Inspector to go back to the script's default.

How do I export a node reference in Godot?

Give the exported variable a node type: @export var target: Node2D. The Inspector then lets you pick a node of that type from the scene. It is set before _ready() runs.

How do I export a slider in Godot?

Use @export_range(min, max, step): @export_range(0, 100, 5) var volume := 80. Add "or_greater" or "or_less" as extra arguments to let values go past the slider.

Coddy programming languages illustration

Learn to code with Coddy

Get started