Lesson 3 of 9 · 27m
Scenes as Composition, Not Levels
Treat every scene as a reusable object boundary, compose large behavior from small packed scenes, and keep ownership at the correct level.
The first breakthrough in Godot is realizing that a scene is not a level file. A scene is a reusable object definition. A projectile is a scene, the player is a scene, a menu panel is a scene, and a level is just a larger composition of those objects. Teams that miss this build one enormous World.tscn and fear touching it.
A scene is a packed tree with a contract
Player.tscn might look like this:
Player (CharacterBody2D)
├── Sprite2D
├── CollisionShape2D
├── Hitbox (Area2D)
└── AnimationPlayerThe root is the public identity. Children are implementation details unless the scene deliberately exposes them. Outside systems should use methods, properties, and signals on the root rather than reaching inside and rearranging private children.
Instantiate instead of copying nodes
Spawning is normal scene composition:
const PROJECTILE_SCENE: PackedScene = preload("res://gameplay/projectile.tscn")
func fire(direction: Vector2) -> void:
var projectile := PROJECTILE_SCENE.instantiate() as Projectile
projectile.direction = direction
projectile.global_position = muzzle.global_position
get_tree().current_scene.add_child(projectile)instantiate creates a fresh object. It does not copy the visible node and does not place itself in the tree. The spawner owns placement; the projectile owns projectile behavior.
Composition beats inheritance for variation
Suppose you need a slime and a spiky slime. Inheritance creates class hierarchies. Composition assembles pieces:
Enemy (CharacterBody2D)
├── MovementBehavior
├── Health
├── Sprite2D
└── optional ThornHitboxA designer can remove ThornHitbox, swap movement behavior, or tune exported values without creating another script class. Inheritance still has uses, but most gameplay variation should be assembled.
Keep scenes independently testable
A good scene can be opened with F6 and demonstrate its behavior with minimal context. When interaction needs a harness, make a small test scene:
TestProjectileRange.tscn
├── DummyTarget
├── ProjectileSpawner
└── DebugOverlayScene boundaries also define ownership. Put state in the smallest scene that truly owns it. The root coordinates its children; children should not quietly command the entire game.
Field notes
res://paths are project paths; do not build them from display names or user-facing text.- Editable children are useful variation points, but they blur the original scene boundary.
- Cyclic scene preloads usually mean shared types or data belong in a third file.
- A scene that cannot run alone is usually coupled to more of the game than it admits.
- Renaming roots, groups, or class names can break code even when the
.tscnstill opens.
Was this lesson helpful?