CodeBlanks Logo Icon CodeBlanks

The _ready method

Learn that _ready is called when the scene is ready.

What is _ready()?

_ready() is a lifecycle method called automatically by Godot when a node and all of its children have entered the scene tree and are fully ready. This method is triggered only once during the lifetime of the node.

extends Node2D

func _ready():
    print("Düğüm hazırlandı!")

Initial Setup

Initial setup tasks such as setting a node's initial position, health value, or accessing other child nodes are done inside _ready(). This is the first safe point where we can be certain child nodes exist.

extends Node2D

var can: int = 100

func _ready():
    position = Vector2(100, 200)
    print("Başlangıç canı: ", can)

Practice Initial Value with _ready

Inside _ready(), define a variable named skor, set its value to 100, and print it to the screen with print(skor).

Starter code

Player.cs
extends Node2D

func _ready():
    # skor değişkeni tanımla ve yazdır
    pass

Sample solution

Player.cs
extends Node2D

func _ready():
    var skor = 100
    print(skor)

Expected output

100

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Which statement is true regarding the timing and frequency of the _ready() function?

  • Called only when a physics step occurs
  • Runs once when the node is deleted from screen
  • Runs once when the node and its children enter the scene and become ready Correct answer
  • Runs continuously on every frame in the game

Explanation: _ready() runs once when the node and all its children are ready in the scene tree.

2 Define the _ready function

Question
extends Node2D

func ____():
    print("Hazır")
Answer
extends Node2D

func _ready():
    print("Hazır")

Explanation: In Godot, the scene entry method is _ready.

3 _ready and Lifecycle

Term Meaning
_ready() Runs when node and children are ready
Tek seferlik Calling frequency of _ready method
İlk kurulum Assigning initial values to variables
Sahne ağacı girişi Event triggering the _ready method

All lessons in Beginner