I don’t think there is an AnimationPlayer override so it is defaulting to the base class.
This is the code that I think handles the connection in AnimationMixer:
/// <summary>
/// <para>Notifies when an animation finished playing.</para>
/// <para><b>Note:</b> This signal is not emitted if an animation is looping.</para>
/// </summary>
public unsafe event AnimationFinishedEventHandler AnimationFinished
{
add => Connect(SignalName.AnimationFinished, Callable.CreateWithUnsafeTrampoline(value, &AnimationFinishedTrampoline));
remove => Disconnect(SignalName.AnimationFinished, Callable.CreateWithUnsafeTrampoline(value, &AnimationFinishedTrampoline));
}
/// <summary>
/// Represents the method that handles the <see cref="Godot.AnimationMixer.AnimationFinished"/> event of a <see cref="Godot.AnimationMixer"/> class.
/// </summary>
public delegate void AnimationFinishedEventHandler(StringName animName);
The AnimationPlayer node has it’s own AnimationFinished event. I’m not sure what you’re trying to achieve here I’m afraid. How come you can’t just use the AnimationPlayer node directly?
Your problem is that the AnimationFinished expects a variable of type AnimationMixer.AnimationFinishedEventHandler. You are attaching a value/function of type Action<StringName>. While these might functionally seem the same, the are two different types for the compiler.
You can fix this by specifying the correct type for your lambda:
// the type is AnimationFinishedEventHandler
AnimationMixer.AnimationFinishedEventHandler AnimationFinishedAction;
AnimationFinishedAction = (StringName animName) => OnAnimationFinished(button);
animationPlayer.AnimationFinished += AnimationFinishedAction;
You mentioned that it worked in other cases. My guess would be that this was for events that don’t pass any parameters. In this case Godot does no create a separate delegate but simply uses Action.
As @tibaverus mentioned I suggest that you specify it as a separate function, then you don’t have to think about the type.
You say that you get the same error, but that shouldn’t be the case. Did you define the function and attached it to the event exactly as @tibaverus showed?
I also see that there is some confusion about AnimationPlayer and AnimationMixer. AnimationPlayer inherits from AnimationMixer and the latter actually defines the animation_finished signal. That’s why the error is in the AnimationMixer class. You probably still want to use AnimationPlayer to have all the ‘extras’ that come with it.