Variables & Data Types
Learn GDScript variables, data types (int, float, String, Array, Dictionary), and type hints for clean code.
No shortcutBeginner6 min readQuick Reference
Variables & Data Types
Godot EngineSelect any node → Click Attach Script button, or Script Editor panel
Best Used For
- ▸Write game logic with variables and functions
- ▸Connect nodes via signals for decoupled systems
- ▸Expose Inspector properties for designer tweaking
Key Settings
Variables store data in GDScript. Godot supports dynamic typing but encourages static typing with type hints for better performance and editor support.
Common types include int, float, String, bool, Vector2/Vector3, Array, and Dictionary. Use var for dynamic or var name: Type for static typing.
Where to Find It
Declare variables at the top of any GDScript file attached to a node in the Inspector.
How to Use
- Basic:
var health = 100creates a dynamic integer. - Typed:
var speed: float = 300.0uses type hints. - Constants:
const GRAVITY = 980for unchanging values. - Arrays:
var items: Array[String] = ["key", "potion"]typed arrays. - Dictionaries:
var player_data = {"name": "Hero", "hp": 100}.
Pro Tips
- Use
@onready varfor node references that resolve after_ready(). - Use typed arrays (
Array[Type]) for better autocompletion. - Prefer static typing everywhere for performance and readability.