How can I make the code to emit signal once the animation is ended?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Loopatronic

Okay, so I’m trying to make a main menu in GD and I ran in to a problem.

extends ColorRect

signal fade_finished

func fade_in():

func on_AnimationPlayer_animation_finished(anim_name):
code end

In the code I wrote to emit signal once animation is ended, and it doesn’t emit it. :confused: I’ve been stuck here for a while now.

:bust_in_silhouette: Reply From: null_digital

Did you connect onAnimationPlayeranimationfinished to the player’s animation_finished?

$AnimationPlayer.connect("animation_finished", self, "onAnimationPlayeranimationfinished")

This code seems to not work, I tried and it doesn’t for me. I found a bug which is corrected since 2018 in github, but it’s not corrected correctly I think.

The best option would be to create a function that emits a signal, I will try it.

cmzx | 2020-09-06 09:50

:bust_in_silhouette: Reply From: selamba

You can also write a function in the script of the AnimationPlayer that will emit a signal, and call it in the animation by adding a function call keyframe. Or just call the function of the receiver node directly.