Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Sprite Resolver: Animations sprite not changing

Discussion in '2D' started by MrCrayons, Feb 14, 2022.

  1. MrCrayons

    MrCrayons

    Joined:
    Jan 3, 2022
    Posts:
    20
    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)
     
    Awufumana and TreeHacks like this.
  2. MrCrayons

    MrCrayons

    Joined:
    Jan 3, 2022
    Posts:
    20
    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.
     
    TreeHacks and ireeenuey like this.
  3. ireeenuey

    ireeenuey

    Joined:
    Jul 10, 2013
    Posts:
    1
    Thank you, was running into the exact same issue and tearing my hair out. This seems to be working for me as well.
     
  4. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    922
    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:
     
    Awufumana, TreeHacks and LaFleur like this.
  5. FashionPunk

    FashionPunk

    Joined:
    Mar 3, 2019
    Posts:
    1
    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.
     
    MarekUnity likes this.
  6. JustinOaksford

    JustinOaksford

    Joined:
    Dec 27, 2022
    Posts:
    3
    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.
     
  7. moksheep

    moksheep

    Joined:
    Dec 7, 2022
    Posts:
    1
    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.
     
  8. FileThirteen

    FileThirteen

    Joined:
    Oct 23, 2012
    Posts:
    52
    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.
     
    Last edited: Sep 7, 2023