Why isn't this code working?

Godot Version

4.4.1

Question

I want to play the animation named ‘money’ after the ‘happening’ animation finishes, and then switch to a new scene.
but this code isn’t working well
This is how this code is running
happening animation → next scene

How does it fail? Make sure to always explain: what you expected to happen and what really happened

Do you get an error in your stack trace or debugger?

2 Likes

i expected the sequence is animation ‘happening’ → ‘money’ → ‘next scene’
but what really happened is ‘happening’ ->‘next scene’ and no money animation..

Is your AnimatedSprite2D’s “finished” signal connected to both functions, _on_happening and _on_money? If so then it will always run both functions, it does not care about what animation was playing, you need to use an if statement to determine which action to take

func _on_animation_finished() -> void:
	if animation == "happening":
		play("money")
	elif animation == "money":
		get_tree().change_scene_to_file("res://etc")
4 Likes

Thank you for this solution

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