Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | jarlowrey |
I have a simple script/node, run an animation and then remove it
using Godot;
using System;
public class OneShotAnimation : AnimatedSprite
{
public override void _Ready()
{
Connect("animation_finished",this,nameof(AnimFinished));
}
private void AnimFinished(){
GetParent().RemoveChild(this);
}
}
Unfortunately this works about half the time, and the other half the completed animation is left onscreen and in the remote scene tree. Why isn’t it running to completion 100% of the time?
HOWEVER, as a workaround, using the frame_changed signal does work 100% of the time.
using Godot;
using System;
public class OneShotAnimation : AnimatedSprite
{
public override void _Ready()
{
Connect("frame_changed",this,nameof(FrameChanged));
}
private void FrameChanged(){
int lastFrame = Frames.GetFrameCount(Animation) - 1;
bool isLastFrame = Frame == lastFrame;
if (isLastFrame) AnimFinished();
}
private void AnimFinished(){
GetParent().RemoveChild(this);
}
}
Though this removes the animatedSprite when the last frame begins, not when it ends.