Skip to content
Tutorials Center
My learning

Topics

Lesson 3 of 36 ยท Getting Started

Your First Godot Project: Hello, World

Build and run your first Godot 4 project: create a scene, add a Label, attach a GDScript, press Play, set a main scene and print to the Output panel, step by step.

Time to make something run. In this lesson you will create a scene with a label, attach a script that prints a message and moves the label, set the scene as the main scene and press Play. These are the same steps you will repeat in every project, so it is worth doing them slowly once.

Godot does not run on this site. The code below is read-only GDScript for the real editor. At the end there is a Python stand-in that imitates the order in which Godot calls your script.

Step 1: make the first scene

With your empty project open, look at the Scene dock on the left. It says "Create Root Node:" with four buttons:

  • 2D Scene (a Node2D)
  • 3D Scene (a Node3D)
  • User Interface (a Control)
  • Other Node

Choose User Interface. A Control node appears and is selected. Rename it by double-clicking: call it Main. Names matter, because scripts refer to nodes by name.

Now add a child: press Ctrl+A (or the plus button), search for Label, select it and press Create. Select the label and, in the Inspector on the right, find Text and type Hello, Godot!. The label appears in the 2D view at the top left. You can drag it, or set the Layout properties later.

Save the scene with Ctrl+S as main.tscn in the project root. A scene file is just a tree of nodes stored in text.

Step 2: attach a script

Select Main in the Scene dock and press the Attach Script button (a scroll with a plus). A dialog opens:

  • Language: GDScript.
  • Inherits: Control (filled in for you).
  • Path: res://main.gd.
  • Template: the default "Node: Default" is fine.

Press Create. The script editor opens with this:

GDSCRIPT
extends Control


# Called when the node enters the scene tree for the first time.
func _ready() -> void:
    pass


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
    pass

Two things to notice right away. First, extends Control says "this script is a Control". Second, _ready and _process are callbacks: you do not call them. Godot calls them at the right moments (The Node Lifecycle explains when).

Step 3: write the code

Replace the body with this:

GDSCRIPT
extends Control

@onready var message: Label = $Label
var speed := 40.0

func _ready() -> void:
    print("Hello from _ready!")
    message.text = "Hello, Godot!"

func _process(delta: float) -> void:
    message.position.x += speed * delta
    if message.position.x > 400.0:
        message.position.x = 0.0

What it does:

  • $Label is shorthand for get_node("Label"): the child named Label. @onready delays the assignment until the node is ready, when children exist. Using $Label in a plain var initializer would give null, a classic beginner error.
  • var speed := 40.0 declares a variable; := lets Godot infer the type (a float).
  • print() writes to the Output panel at the bottom of the editor.
  • In _process, we move the label to the right by speed * delta each frame. Multiplying by delta (seconds since the last frame) makes the movement the same on a 30 fps and a 144 fps computer. Without it, a faster computer moves the label faster.

Step 4: run it

Press F5 (the play icon at the top right). Because no main scene is set, Godot asks: "No main scene has been defined. Select current scene?". Choose Select Current, and Godot stores res://main.tscn as the main scene in project.godot. A window opens, the label slides across and the Output panel shows Hello from _ready!.

Close the game window (or press F8 in the editor) to stop.

The other run buttons: F6 runs the scene you are editing (handy for testing one scene on its own); F5 runs the main scene.

sequenceDiagram
    participant E as Engine
    participant M as Main (script)
    E->>M: _ready() once
    loop every frame
        E->>M: _process(delta)
    end

The engine calls your callbacks; you do not.

Understanding the Output and Debugger

At the bottom of the editor are the panels you will use all the time:

  • Output: your print messages.
  • Debugger: errors with a stack trace, a profiler and a monitor of performance values. A red error on a line means a script error; double-click it to jump to the line.
  • Audio, Animation and other panels appear when relevant.

Try breaking the code on purpose: change message.text to mesage.text, run and read the error. Learning to read the Debugger is a bigger win than any trick.

Stand-in: the order of callbacks

This Python code is not Godot. It simulates a tiny main loop that calls _ready once and _process each frame with a fixed delta, so you can see the order and the effect of multiplying by delta.

Python Stand-in (Python): _ready once, _process per frame

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Both runs end at 40.0, because speed is "pixels per second". Remove * delta in your head and the 144 fps machine would move almost five times farther.

Common mistakes

  • Forgetting to save the scene or script before pressing Play. Godot saves automatically on run, but a new scene must have a path.
  • A script attached to the wrong node: check the little script icon next to the node name.
  • $Name is null: the path is case-sensitive; with var outside @onready the node does not exist yet.
  • Mixing tabs and spaces causes "Mixed use of tabs and spaces for indentation" errors.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which key runs the project's main scene?

    F5 runs the main scene. F6 runs the scene currently open, and F8 stops the running game.
  2. 2. Why use @onready for var message: Label = $Label?

    Children are not available when the script's variables are first initialized. @onready delays the assignment until just before _ready runs.
  3. 3. Why multiply movement by delta in _process?

    delta is the seconds since the previous frame, so speed * delta gives the same movement per second at any frame rate.
  4. 4. Where does print() write its output?

    print() appears in the Output panel in the editor (and in the console of an exported build).

Summary

  • A project starts with a scene: a root node plus children, saved as a .tscn file.
  • Attach a script to a node to give it behavior; extends names the node type it builds on.
  • _ready runs once, _process(delta) every frame. Multiply by delta for frame-rate independent motion.
  • @onready var x = $Child safely fetches a child node.
  • F5 runs the main scene, F6 the current scene, F8 stops.

Next: Project Structure and Files