Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice

Resolved Is there any way to disable the animator's automatic interpolation of a specific bone?

Discussion in 'Animation' started by aquaclaw9, Sep 7, 2023.

  1. aquaclaw9

    aquaclaw9

    Joined:
    Mar 8, 2016
    Posts:
    4
    So, I've admittedly got a bit of a strange setup going with my character models and how they are animated, so this might be far beyond the use-case of Unity's animator but I'll shoot my shot anyway.

    All of the character models in my game have a script attached to them that (among other things) change the sprite of their face to one that matches the specified ID (stored as a public int, when it changes, the sprite changes)


    This is the property in question, "Expression ID"

    I've been animating this int through Unity's built-in animation system and using "constant" on both tangents to make sure it's going to the right IDs directly and not interpolating between them which was fine until I started using it to interpolate between animations in the animator.


    This is how the animation curve for this property looks in the animator


    This is the animator transition that's interpolating between the two animations.

    When it interpolates, if it's interrupting an animation that had the face ID at 6, with one that has an ID of 0, it would quickly switch between 6, then 5, then 4, 3, 2, 1 and finally 0, all within the span of the transition duration, which is not ideal to say the least.

    Basically, is there a way to set a bone or other animatable property to ignore the animator's transition's interpolation?
    Worst case-scenario I'll either just not interpolate any of the animations that have faces besides the default, but I'd like to solve this if possible.

    I realize that this could probably be solved by using an enum for the value of the face, but because of the kinda funky setup going on that's not really an option. (ID refers back to a scriptable object with a list of faces, this list is of variable length, so enums won't really work)

    Either way, thank you for reading and for your time!
     
  2. aquaclaw9

    aquaclaw9

    Joined:
    Mar 8, 2016
    Posts:
    4
    Ok, so I think I've figured it out, at least for my use-case.

    I was fiddling around, clicking everything I could in the editor when I thought "If this option were to be somewhere, it's probably one of those things like [Range(0, 10)] you add before declaring stuff (I never learned what they were called lmao)"

    So I started just looking through all the autocomplete options in visual studio, in particular after UnityEngine.Animations, and I found [UnityEngine.Animations.DiscreteEvaluation] which is exactly what I was looking for!

    This unfortunately doesn't work for regular bones as far as I'm aware, but for an int on a monobehavior it's perfect!!

    Didn't work at first, but I fiddled around and to be honest, I have no recollection of what I did differently but it seems to be working now.

    If anyone finds this, here is what I did to get it to work.

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Animations;
    3.  
    4. public class emptyTest : MonoBehaviour
    5. {
    6.     [UnityEngine.Animations.DiscreteEvaluation]
    7.     public int testValue;
    8. }
    tl;dr - Add [UnityEngine.Animations.DiscreteEvaluation] before the attribute in question, documentation here: https://docs.unity3d.com/ScriptReference/Animations.DiscreteEvaluationAttribute.html

    If you are using a normal bone, my first thought would be to create a script that manually sets the transform of the bone on LateUpdate() or something, animating that instead of the normal bone and putting this property on the values in the script.​
     
    Last edited: Sep 11, 2023
    tsukimi likes this.