Sprite Resolver: Animations sprite not changing

Hi everyone,

I’ve attempting to use the Sprite Library and Sprite Resolver to optimise my project and make things easier for character customisations.

I’ve used the Sprite Resolver to add my sprites into each actions animations, however when I perform an action in the game preview (e.g. jump) it flickers for a fraction of a milisecond and then reverts to the idle state sprite it started up with.

When playing the raw animations in the correct sprites are in there. But when previewing the game the sprite doesn’t change when jumping.

I’m hoping I’ve just missed something really obvious but if anyone has any suggestions on what it might be it would be very much appreciated.

(I’m using 2D animation package versions 5.0.9)

3 Likes

An update incase anyone has this same problem. Rebuilding the animator from scratch seemed to do the trick. Not sure why and it was a big pain, but the main thing is it works.

2 Likes

Thank you, was running into the exact same issue and tearing my hair out. This seems to be working for me as well.

Could it be that your Animator Controller contains clips animating both the SpriteRenderer.sprite and the SpriteResolver?
If so, see this section from the 2D Animation documentation:

5 Likes

I’m going to necro this thread because after struggling with exactly this issue for a few hours I believe I found the correct solution.

The animator layer had been set to “additive” in the layer settings with only one layer in the animator. Setting the layer back to “override” corrected the issue for me.

1 Like

I just wanted to flag that this was apparently the issue for me as well, after struggling for 5+ hours researching how to solve this issue.

To be clear; I had explicitly deleted the “Sprite Renderer” Properties from all of the animation clips but whatever residue from that existed seems to be messing it up.

After suffering from similar problems for hours, I found another way. In my case, I tried to change my image to Sprite Resolver, but it didn’t work. So I “delete” it from the animation but it didn’t work out the same way either.

I don’t know why, but I got rid of the sprite change in the anime window, but it seemed like there was a chigge left, and there was no change even if the engine was turned off or off.

So here’s how I found it:

  1. Remove all animations from the Unity Resources folder, then put them back in.
  2. Then open the anime window and you’ll see the dregs that were originally deleted! Surprisingly…
  3. Erase it again.

Got me on this thread by google search, but I hope people suffering for similar reasons can help.

1 Like

I’m seeing something similar but maybe not exactly the same. I originally had the same issue, I was trying to do a side by side comparison so I originally tried just using an animator controller override and duplicating all my animations, attaching the duplicated ones to the override controller and then deleting all the SpriteRenderer.sprite keys in the animation and animate the SpriteResolver but the keyframes wouldn’t take the value of the sprite hash. I found this thread and deleted all those animations, animator, and tried duplicating the animator and swapping out for the new animations which also didn’t work. So I finally rebuilt the whole animator from scratch with brand new from scratch animations which now seem to be getting the hash in the key frames but the sprite isn’t showing the change when played back, if I just scrub through the animation the frames show but not when doing the playback. Another thing I notice is the animation seems to end early. Normally if you had 2 frames of animation the animation plays through and restarts at the beginning of frame 3, I have 2 frames for my walk with this and it seems to only be playing the first frame and restarting at the next one…

Edit 1: Sure enough duplicating the last frame and moving it out or adding literally any key frame at the end causes it to play the full animation properly.

Edit 2: Well continuing through the process sometimes I just have animations that work and sometimes I don’t. I’m following the same process for all of them, from scratch, only exists in the animator that is for sprite swapping and half the time when I’m trying to keyframe out the sprite hash it just doesn’t work. I go through each frame, set the options on each and then I scrub back through and all of them are set to just the same hash the first frame is showing.

Edit 3: Turns out the reason some of my animations weren’t working properly is cause I had not consistently remembered to modify the tangents and stuff on the keyframes. At current state I feel like this system is pretty obtuse, hopefully it will get better. At current, for sprite sheet based animations, where it’s possible to make sure your sheets are built the same with the same ordering I think a script that just swaps out the sprite in LateUpdate is far more efficient than creating a whole SpriteLibrary for each different kind of thing. You have to remember a bunch of extra stuff and creating the animations is normally pretty easy, drag and drop multiple sprites onto a sprite renderer vs building out each SpriteLibrary, setting up your animation keyframes to be broken/constant, and ensuring you have an extra key frame so your actual last frame plays out all the way. One way I think this maybe could be improved, and it might be doable through editor scripting, is basically build a single sprite library based on a sprite sheet and be able to build more sprite libraries automatically from that sprite librarie’s sprite ordering. That would certainly streamline things. Also having the animator recognize the hash keyframes as a value to play out a frame for would be nice, finally not having to set to constant/broken on each keyframe would be good, an editor utility could probably do that too by editing the metadata of multiple selected animations.

1 Like

How this issue in not fixed yet in 2024…

I have the same flickering bug and nothing written by other guys above helps.

I have added extra keyframes in the end, made sure that all animations are Broken/Both Constant.
I have created new animator set to Override mode and populated with my old animations.
Tried to delete Library folder to reimport all.
I also tried to update all Sprite Resolvers after animation transition using spriteResolver.ResolveSpriteToSpriteRenderer()

Nothing helps the flickering and slight dispositioning of sprites during play mode.

All animations work fine in animations tab in editor. Of course I have seen Sprite Swap limitations, but I have only Sprite Resolver animated, no Sprite Renderer keyframes anywhere.

P.S. I have my character made with separate body parts. So I have parent gameobject with Animator and I have Head, Body and Sword as children, each with it’s own Sprite Library and Sprite Resolver.
I thought several Sprite Library scripts may somehow conflict on same Prefab, but when I deleted all parts except head, the head flickered like before…

If someone found the new solution it would be really helpful!

Amfibrachy Would you be able to submit a bug report so that I can investigate the issue thoroughly on my side with a minimal repro project? That would be really helpful to understand what’s causing it and how to solve it. Thanks!

Thanks for quick response! I hope it’s a bug and I’m not missing something.
My project is small, around 100mb with a single scene. But with unity Library it’s 4GB. Should I pack whole 4GB or delete Library folder and pack what is left?

You don’t need to include Library, or Temp folders. The most important folders are Assets, Packages, and ProjectSettings. If you use Help → Report Bug menu in the editor the bug reporting tool should pack everything for you automatically. If you prefer to share the project with me directly, you can do that in a private message, but please specify which Unity version you are using and your OS.

Amfibrachy I looked into your project and the issue was that your Sprite Resolver animations were using both the new Sprite Hash as well as legacy Sprite Key and Category Hash and Label Hash.

In your instnace the solution to the flickering issue is to remove the legacy Sprite Key, Category Hash and Label Hash from animation clips. You can do this using the automated tool vailable inside the 2D Animation package called the 2D Anim Asset Upgrader. I’ve sent you a detailed description on how to use in your project in a private message.

Please let me know if it solved your problem!

2 Likes

Thank you!
Using Asset Upgrader on animation clips solved the flickering issue for me. Though I’m not sure why I needed it in the first place, since I used latest versions of unity from the start.

This solved the problem. I had 10 animations in my Animator Controller, but one of them was mistakenly changing the sprite using both the Sprite Renderer and the Sprite Resolver. Because of that, the other animations were not working. When I deleted that animation, all the other animations started working fine.