Search Unity

Question Swapping Override Controller At Runtime Resets Animator Rig Constraint Weights To Default.

Discussion in 'Animation' started by Malghull, Jun 3, 2023.

  1. Malghull

    Malghull

    Joined:
    Sep 28, 2017
    Posts:
    2
    Hi Guys!

    I have been banging my head against this problem for about a week now, so if anyone has any advice, thank you in advance!

    I have several Animator Controller Overrides for my characters which I swap depending on what weapon they're holding (weapon stance). I recently added an animator rig to my character to make the character properly aim at the target and ensure the hands are in the proper positions for the weapons. I have a script set up where, if the character equips a weapon, the constraint (two-bone IK constraint) weight smoothly lerps from 0 to 1 in 0.5s, and when unequipped it goes from 1 to 0 in 0.5s. I saw that whenever the animator runtimeAnimatorController got swapped out, the constraint weight would reset back to its default value for several frames which makes the arm look like its snapping back and fourth.

    Things I've tried:
    • I've tried turning off write default on all of my animation states but that actually made me unable to edit the constraint weight period for some reason.
    • -I've tried to copy and paste the animation state and parameters in code immediately after swapping out the runtimeAnimatorController but that resulted in some weird behaviour for other animations and did not stop the constraint weights from resetting.
    • I've set the Constraint weight values immediately after changing the runtimeAnimatorController but that doesn't take effect until several frames after.
    • Loads more messing around with setting here and there but nothing changed.
    Once again thank you in advance!