How to change scene to next scene

Godot Version

4.4.1v

Question

Could you please tell me the code to transition to the next scene after a sprite animation finishes?

It depends on what you are trying to accomplish. If you want to load an entirely new scene, you would instantiate it into your Main scene and free the current one.

You must use the animation_finish signal of the animatedsprite node and that’s it

I’ll explain how to switch to another scene after your sprite animation finishes in Godot 4.4.1.
Your script is already good — you just need a small addition to load the next scene.
extends AnimatedSprite2D

extends AnimatedSprite2D

var repeat_count = 0
var max_repeats = 3

func _ready():
play(‘call’)
connect(“animation_finished”, self, “_on_call_finished”)

func _on_call_finished():
if repeat_count < max_repeats:
repeat_count += 1
play(‘call’)
else:
# Here you change the scene!
var new_scene = load(“res://Path/To/YourNextScene.tscn”)
get_tree().change_scene_to_packed(new_scene)

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.