1. A scene is a tree
3 minRead any scene by asking which node owns what.
Owns the motion. This is the node the script attaches to, and it is the scene's root, so instancing Player.tscn anywhere gives you the whole tree.
- Why it is here
- A physics body has to be the root: the children move because it moves.
- Coming from
- Unity: the GameObject with a CharacterController and the script on it. Unreal: a Character.
- In the Inspector
motion_mode = Grounded
Godot has no GameObject and no components. A scene is a tree of typed nodes saved as a .tscn file: the root decides what the scene can do, and each child adds one responsibility. Click the nodes of a real Player scene to see what each one is for and why it sits where it does.
Coming from Coming from Unity: the root is the GameObject and the script together; each child is what a component used to be. Coming from Unreal: the root is the Actor, the children are its components.
To finish: Open all five nodes.
Notes
The written version of this lesson, for after you have done it.Every scene in Godot has exactly one root, and the root's type is the first decision you make. A CharacterBody2D root means the scene can move and collide; a Control root means it lays out UI; an Area2D root means it detects. Children never change what the root is, they add to it.
Children inherit their parent's transform. That single rule is why the camera follows the player, why the collision shape moves with the body, and why the footstep sound comes from where the player stands. There is no follow script and no parenting code; the tree does it.
When you open someone else's project, read the tree before the scripts. The root tells you the scene's job, the children tell you its responsibilities, and the scripts only fill in behaviour on nodes that already own their state.
Try it in the editor five minutes, in a real project
- Open Godot, create a 2D scene, and make the root a CharacterBody2D. Rename it Player.
- Add three children with the plus button in the Scene dock: Sprite2D, CollisionShape2D and Camera2D. Give the shape a CapsuleShape2D in the Inspector.
- Move the Player node in the viewport. Every child moves with it; that is the transform inheritance the lesson showed.
- Press Ctrl+S and save it as player.tscn. Open the file in a text editor and find each of the four nodes by name.
PlayerCharacterBody2D- Owns the motion. This is the node the script attaches to, and it is the scene's root, so instancing Player.tscn anywhere gives you the whole tree. A physics body has to be the root: the children move because it moves. Unity: the GameObject with a CharacterController and the script on it. Unreal: a Character.
Sprite2DSprite2D- Draws the texture. It has no physics and no logic; it is only what you see. A child of Player so it moves with the body without any code. Unity: SpriteRenderer. Unreal: a PaperSprite component.
CollisionShape2DCollisionShape2D- Gives the body its shape. Without this child the body never collides with anything and is_on_floor() is never true. The shape belongs to the body it describes, so it lives directly under it. Unity: CapsuleCollider2D. Unreal: the capsule component on a Character.
Camera2DCamera2D- The view follows the player because the camera is the player's child. Smoothing and limits are properties, not code. Children inherit the parent's transform, so following is free. Unity: a Cinemachine virtual camera set to follow. Unreal: a SpringArm and Camera component.
FootstepAudioAudioStreamPlayer2D- Plays a sound from the player's position, so it pans and fades with distance. Positional audio has to sit on the thing that makes the sound. Unity: an AudioSource with spatial blend. Unreal: an AudioComponent.