To check if an animation exists before playing it in Godot using the spine-godot runtime, you can use the SkeletonData to verify the presence of the animation. Here's how you can implement this in C#:
public void SetAnimation(string animation, bool loop) {
var skeletonData = GetSkeleton().Data;
if (skeletonData.FindAnimation(animation) == null)
return;
GetAnimationState().SetAnimation(animation, loop, 0);
}
This code snippet uses FindAnimation on the SkeletonData to check if the animation exists. If the animation is not found, it returns early, preventing any errors from occurring when trying to set a non-existent animation.