Problem playing animation

Hello everyone,

I try to make a gameobject able to play animations stored in a list
I have this error when i try to play an animation :
Default clip could not be found in attached animations list.
UnityEngine.Animation:play ()

This is my code :

public class Animation_ : MonoBehaviour
{
    private Animation animComponent;

    public AnimationClip animation1;
    public AnimationClip animation2;


    private void Awake()
    {
        animComponent = GetComponent<Animation>();
        animComponent.clip = animation1;
        animComponent.clip.legacy = true;
        animComponent.Play();
    }
}

The animation i try to play is marked as legacy (set in debug mode).

This error diseapear when i change my code :

public class Animation_ : MonoBehaviour
{
    private Animation animComponent;

    public AnimationClip animation1;
    public AnimationClip animation2;


    private void Awake()
    {
        animComponent = GetComponent<Animation>();
        animComponent.clip = animation1;
        animComponent.clip.legacy = true;


        animComponent.AddClip(animation1,"animation test");
        animComponent.Play("animation test");
    }
}

But with this code nothing happen(no error, no animation, nothing)

I added a screenshoot of the gameobject and the legacy set in debug mode
Can you help me?

You need to create the “Legacy Animation”
Attach the empty Animation component first and hit Ctr+6 (Will popup the ANimaiton Window)
Then press the the record button and animate like you want, and it will work.

if you have created a Non-legacy animation in the beginning, selecting Legacy bool won’t work.

If you have done as I say and still not working then attach a minimal project with animation and script, will investigate.

I tried your idea without sucess.
However this below do the job

    private SpriteRenderer spriteRenderer;
    public List<Sprite> sprites;

    private void Awake()
    {
        StartCoroutine(DisplaySprites());
    }

    IEnumerator DisplaySprites()
    {
        foreach (Sprite sprite in sprites)
        {
            spriteRenderer.sprite = sprite;

            yield return new WaitForSeconds(0.2f);
        }
        OnAnimationEnd();
    }

    private void OnAnimationEnd()
    {
        gameObject.SetActive(false);
    }

You had spritesheet?

You can drag all the sprites to the animation window and can make animation

Yes i did this however my problem is that nothing is displayed.
I achieve to set the animation in animation component without “Default clip could not be found in attached animations list”
But nothing is displayed.

For exmple i set unity with the parameters on image → nothing happen.
I set the code bellow → nothing happen (i tried both method animation_.Play)

    private Animation animation_;
    void Start()
    {
        animation_ = GetComponent<Animation>();

        Debug.Log(animation_.clip);
        animation_.Play();
        animation_.Play("New Animation");
    }

legacy is selectionned