UI Button onClick Events have no "animation.play()"

Hi there,

I have gameobject A with a button-component and gameobject B with an animation-component (legacy since it’s cheaper).
When I use the buttons “On Click” in the inspector - not in the script, in other words: drag’n’drop the gameobject B into and look at the dropbown-menu, choose the “animation”-component, I can’t seem to find the “play”-function. I could use the “blend”-function but I think this costs more than just play without blend.

Did I miss something or do I have to make it with an extra script?

I believe it is because the Play method on the Animation has a return type of bool, and is therefor not an Action<>. I’ve tested this by creating other components, and only the void-returning methods show up in the OnClick handler. Here’s a little helper component I made to get around it.

[RequireComponent(typeof(Animation))]
public class AnimationTrigger : MonoBehaviour
{
    private Animation _animation;

    private void Awake()
    {
        _animation = GetComponent<Animation>();
    }

    public void Play()
    {
        _animation?.Play();
    }
}