Search code examples
scenegodotgdscript

Godot - Changing the scene


I am working on a breakout game and I need to reload the scene when the ball hits a wall. Here is the code:

extends RigidBody2D

func _ready():
    set_fixed_process(true)

func _fixed_process(delta):
    var caramizi = get_colliding_bodies()

    for caramida in caramizi:
        if caramida.is_in_group("caramida"):
            caramida.queue_free()
        elif caramida.is_in_group("die"):
            #reload the scene
            pass

How to reload the scene?


Solution

  • The SceneTree has a reload_current_scene method. You should be able to use it with:

    get_tree().reload_current_scene()
    

    http://docs.godotengine.org/en/stable/classes/class_scenetree.html