Sprite swap animation not working

I was going to make one shared frame-by-frame animation clip for different kinds of doors(or anything that can be “opened”), and I planed to achieve that with sprite library. As a test, first I created two sprite library assets. Here’s one of it:
7328962--890173--upload_2021-7-15_12-21-35.png
Following the manual of 2D Animation, I added Sprite Library and Sprite Resolver to the door game object and recorded the animation. Both Tangents for each frame was set to Constant.


Problem: The animation works fine in preview, but doesn’t work in play mode.
In play mode the door just flickered weirdly when the animation is played. When I opened Curves in the clip, it shows nothing, but an error saying:

Mesh ‘ControlPointRendererMesh’: abnormal mesh bounds - most likely it has some invalid vertices (+/-inifinity or NANs) due to errors exporting.
Mesh bounds min=(33.00, 0.00, 0.00), max=(981.00, 45339354241005009240064.00, 0.00). Please make sure the mesh is exported without any errors.
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)


It seems to be the same problem in Sprite Resolver: Animation Doesn't Work In Runtime
I am working with Unity 2021.1.11 and 2D Animation 6.0.4.
I haven’t found any solution. How can I fix that?

Hello @Oksh ,
The error you see when switching to the Curves window is an unfortunate error, but it should not impact the animation clips ability to playback. The error is shown since the Curves window has an issue with the large hashing values we are using for Sprite Key.

When you say “it works in preview”, does that mean that you have selected the GameObject and pressed Play in the Animation window? If this works, then it seems like there is something other than the clip that is interfering with the playback. How is your Animator Controller setup? and do you have any other scripts that might update the SpriteRenderer.Sprite property?

Here’s the Animator Controller:
7329934--890350--upload_2021-7-15_19-9-22.png
7329934--890353--upload_2021-7-15_19-9-36.png

And here are all the components attached to the door GameObject:
7329934--890359--upload_2021-7-15_19-10-27.png

The Door script is all about player interactions (SceneTravelBase is about scene loading):

public class Door : SceneTravelBase, IInteractable
{
    private Animator animator;

    [SerializeField]
    private AudioClip openSound;


    void Awake()
    {
        animator = GetComponent<Animator>();
    }

    public virtual void Interact()
    {
        OpenDoor();
    }

    protected void OpenDoor()
    {
        AudioManager.Instance.PlaySound(openSound);
        animator.SetTrigger("Open");
        SceneTravel();
    }

    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.CompareTag("Player"))
        {
            var player = collision.GetComponent<Player>();
            if (!player.interactObjs.Contains(this))
                player.interactObjs.Add(this);
        }
    }

    private void OnTriggerExit2D(Collider2D collision)
    {
        if (collision.CompareTag("Player"))
        {
            collision.GetComponent<Player>().interactObjs.Remove(this);
        }
    }
}

I did another test by making the animation loop. Here’s how it looks in play mode:
7329934--890401--2021-07-15-19-28-19.gif
While in the inspector of door:
7329934--890404--2021-07-15-19-27-06.gif

I can’t figure out why. Does URP has anything to do with it?

Thanks for sharing all this information. Unfortunately I couldn’t spot any issue with your setup. Would you mind sending me the project (or a downsized version of it) in a PM? Then I can take a closer look.

Sorry I’m new to Unity, does PM means exporting the project to an unitypackage? I’ve pushed my project to Github: https://github.com/HotranLandoler/CQU-Horror , will that help?

Github works perfectly. Thanks!
For future reference, you can click my username to see my forum profile. There you can click “Start a conversation” to send a PM (private message).

So looking at the project, what I noticed was that your B5door.controller contains clips which animates both SpriteResolver.SpriteKey value and SpriteRenderer.Sprite.
Due to how the Animation system works, you cannot mix and match the two in the same controller. To fix your issue, convert all the animation clips to only animate SpriteResolver.SpriteKey or SpriteRenderer.Sprite.
You can read a bit more about it here.

I removed the sprite clip and it works! That clip was obsolete and I planed to remove it later, but didn’t know it will cause problem. Thanks a lot for your help.