Changing Scene when Animation is Over

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Bush2Tree
:warning: Old Version Published before Godot 3 was released.

My problem is really simple, but I can’t wrap my head around it. What I’m trying to do is to play an animation, and then switch scenes. Here’s the code that I want to improve:


extends Control

onready var animplayer = get_node("../../AnimationPlayer")

func _input_event(ev):
	if (ev.type==InputEvent.MOUSE_BUTTON and ev.button_index==BUTTON_LEFT and ev.pressed):
		animplayer.play("AnimationPlayer")
		get_node("/root/globals").setScene("res://Scenes/levelselect.scn")

func _ready():
    pass

I couldn’t find a solution to my problem, so I came here. Thanks in advance!

:bust_in_silhouette: Reply From: Cryingpants

You can call functions with your animation just by pressing the ‘+’ in the bottom right corner in the animation setup. So if you just make a function in your script, then you can call that function when the animation is over.

:bust_in_silhouette: Reply From: volzhs

You can do it with signal.

animplayer.connect("finished", get_node("/root/globals"), "setScene", ["res://Scenes/levelselect.scn"])
animplayer.play("AnimationPlayer")