Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

SpriteResolver + AnimationController/Override issues

Discussion in '2D' started by massivebacon, Feb 12, 2021.

  1. massivebacon

    massivebacon

    Joined:
    Apr 24, 2014
    Posts:
    27
    Hey all!

    I'm using the new 2D stuff in my game and really loving it. Thanks for putting it together! Beats having to generate hundreds of unique animations for sprites that all share the same format sheets!

    I'm currently running into issues though with using AnimationControllers and SpriteResolvers/SpriteLibraries. I've done a frame animation properly as indicated in the docs (animating the label hashes, and set those initial keyframes by recording the values being entered by clicking the sprites in the inspector, so the hashes are right). When I preview the animation at edit time it looks fine, with the sprite resolver properly updating and the SpriteRenderer showing the right sprite.

    However, also on this component is an animation controller. I've got a few states on it and am mostly just testing one state right now that does a basic animation through label hashes.

    In Play mode, I can see the sprites updating in the resolver properly, however the sprite in the SpriteRenderer keeps getting reset to it's initial value (from the prefab). This means that the animation doesn't play back correctly at runtime, and results in a "flickering" sprite, where the sprite is swapping between it's animating values and the default sprite. If I even watch the inspector closely I can see the reference to the sprite in the SpriteRenderer itself flicker as it is swapped between the proper animated sprite and the default sprite.

    Would love some help here or any guidance on what to do!
     
    christh likes this.
  2. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    875
    Hello @massivebacon
    Do you have any script or other components that might interact with the Sprite value in the SpriteRenderer, apart from the SpriteResolver?
    Do you have two animation clips running at the same time that might fight over which Sprite value to use?
     
  3. massivebacon

    massivebacon

    Joined:
    Apr 24, 2014
    Posts:
    27
    Thanks for getting back Ted. No other components on the object that would affect the renderer and nothing with a reference to it that's updating it. I'm using the same rig I had setup before with the hardcoded sprite animations and am just testing swapping the single idle/default animation with a label animation. In mechanim I see the animation properly looping on the state, and the animation is bound to the right animation, but as I mentioned above the sprite keeps defaulting back to the prefab value.

    I'm going to try some other things today to see if I can figure out what's going on.Worth noting as well that I'm building the library at runtime through scripting and assigning it as the library for the object. The library name is updating properly on the Library component and I can see the correct sprites in the component, but maybe when the library switches something is breaking with the tie to the SpriteRenderer?
     
  4. massivebacon

    massivebacon

    Joined:
    Apr 24, 2014
    Posts:
    27
    I recorded a gif of what I'm seeing:



    The SpriteRenderer sprite is from the prefab value. The Library is properly being loaded and assigned, and you can see that the animation is working. However the Renderer won't stop reverting to the prefab value.
     
  5. massivebacon

    massivebacon

    Joined:
    Apr 24, 2014
    Posts:
    27
    @Ted_Wikman After looking into this more today I think this may be an issue with Mechanim animations? I saw that the inspector for the sample project animations looked different than any animation I created (the sample projects only have a "Wrap Mode" dropdown), and I found this forum post that says there is a difference between old animations and new animations where new animations are default mechanim. A mechanim animation version of the animation (Create -> Animation) and an old animation (created by duplicating the Scavengers animation and changing the hashes), played back in the same gameobject, result in the mechanim animation not properly playing back, and the old animation working.

    Further, when I use the "old" animation type in my GameObject and forgo the mechanim rig and just play back the single old animation, the object "works". In the sample project, you all have no examples of frame animations running with mechanim in the SpriteSwap section, and the Flipbook samples you do have use the old animation clip style and don't interact with mechanim, so I'm wondering if this was an oversight.

    Said differently, it seems like right now the Flipbook animation style is unable to work with mechanim and requires "old" animations.
     
  6. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    875
    Thanks a lot @massivebacon for taking a close look at this. Do you mind filing a bug report regarding this, and paste the bug report ID in this thread? Then we can take a closer look at this issue.
     
  7. massivebacon

    massivebacon

    Joined:
    Apr 24, 2014
    Posts:
    27
    Hey @Ted_Wikman - spent a bit of time this weekend trying to narrow down the bug. I made a new project and tried to set everything up but couldn't get the bug to reproduce. I then went back to my main project and just kept subtracting things from the problem prefab until I basically had a standard "example" object that was still exhibiting the issue. I then compared it with the most basic "working" version and finally narrowed down the bug (bug report to be filed later today).

    It seems that if there are any other states in the mechanim layer that is currently playing the label animation, even if they aren't connected to the flow, the bug will exhibit.

    This is the most simple mechanim flow I could get to exhibit the bug. The "test" state has a looping label animation on it, which will work as long as the "other" state isn't there. If the "other" state is present, the bug exhibits. Deleting the "other" state makes the bug go away.

    upload_2021-2-16_10-59-18.png
     

    Attached Files:

    christh and DietPippu like this.
  8. massivebacon

    massivebacon

    Joined:
    Apr 24, 2014
    Posts:
    27
    Bug report filed @Ted_Wikman. Putting together the report helped me further narrow down the issue.

    It seems like the core issue is that, if a label-based animation and sprite-based animation share the same layer in mechanim, the bug will happen. In the above image I posted, "other" had a sprite animation in it, while "test" had a label animation. Swapping the animation in "other" to be null or to be a label animation makes the problem go away.

    I ran into this because I was switching over my old animation rigs to use labels, so in the transition point when I was testing, the animations were bugged because a given layer has a mix of animation types on it.

    I'd like to have both be able to exist at the same time.

    Also, it seems like there is maybe an issue with using Label-based animations to override sprite animations on an animation overrider controller, though I haven't directly tested this yet.
     
    Last edited: Feb 16, 2021
    christh likes this.
  9. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    875
    Thanks a lot for going the extra mile and creating a detailed way to repro this issue. I've managed to repro this issue as well on my computer. You will receive updates through the fogbugz link, and I will also write an update in this thread once the issue is resolved.
    Thanks again for your help!
     
    christh and massivebacon like this.
  10. YaGa

    YaGa

    Joined:
    May 18, 2014
    Posts:
    2
    Is this still being looked at? I have the same issue. I updated all my old sprite based animations to the label based sprite resolver animations. I've also followed the documentation.
     
  11. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    875