GDScript Crash Course for Unity C# Developers

Learn GDScript quickly if you're coming from Unity's C#. A practical syntax comparison with examples to get you productive in Godot fast.

GDScript code comparison with C# showing syntax differences

Coming from Unity's C#? GDScript will feel familiar in many ways—it's dynamically typed, Python-inspired, and designed specifically for game development. This crash course gets you up to speed quickly.

Basic Syntax Differences

gdscript
# GDScript uses indentation instead of braces
func _ready():
    var message = "Hello, Godot!"
    print(message)

# Compare to C#:
# void Start() {
#     string message = "Hello, Unity!";
#     Debug.Log(message);
# }

Variables and Types

GDScript supports both dynamic and static typing. You can use type hints for better code clarity and editor support.

gdscript
# Dynamic typing
var health = 100
var player_name = "Hero"

# Static typing (recommended)
var health: int = 100
var player_name: String = "Hero"
var velocity: Vector2 = Vector2.ZERO

Lifecycle Methods

Godot's lifecycle methods are prefixed with underscores. Here's the mapping from Unity:

gdscript
# Unity -> Godot
# Awake() -> _init()
# Start() -> _ready()
# Update() -> _process(delta)
# FixedUpdate() -> _physics_process(delta)
# OnDestroy() -> _exit_tree()

Signals (Events)

Godot uses signals instead of C# events. They're built into the engine and incredibly powerful.

gdscript
# Define a signal
signal health_changed(new_health)

# Emit the signal
func take_damage(amount: int):
    health -= amount
    health_changed.emit(health)

# Connect to a signal
func _ready():
    player.health_changed.connect(_on_health_changed)

func _on_health_changed(new_health: int):
    health_bar.value = new_health

Node References

gdscript
# Get a child node
@onready var sprite = $Sprite2D

# Get a node by path
@onready var health_bar = $UI/HealthBar

# Export for inspector
@export var speed: float = 200.0
@export var jump_force: float = 400.0

Next Steps

You now know the GDScript basics! The best way to learn is by building. Try recreating a simple Unity project in Godot—the patterns will quickly become natural.

👤
Godot Learning Team Helping developers transition to Godot with practical tutorials and comparisons.