Search Unity

Why does Animator.pivotWeight always return 0.5f?

Discussion in 'Animation' started by Amuwaru, May 27, 2020.

  1. Amuwaru

    Amuwaru

    Joined:
    Dec 17, 2019
    Posts:
    16
    Hello,
    I've been trying to use this float to figure out which foot I should apply IK on dynamically:
    https://docs.unity3d.com/ScriptReference/Animator-pivotWeight.html

    but...
    Animator.pivotWeight returns 0.5f every time I read it.

    I've tried different setups and different locations where I could call it (like update or OnAnimatorIK to see if it changed eventually, or if it was overridden at some point by something else, but nothing happened.

    I've tried looking this up everywhere and so far no clear answers, so I'm asking again to see if anyone has figured this out before.
    Is it deprecated? (because I've seen people claim this... "works"?)
    or perhaps I'm using it incorrectly?

    If it doesn't work, is there a better alternative than having to go through the hassle of modifying curves in the original animation FBX files? (because that gets nasty real quick when you have a lot of animations)

    By the way, my character is using an Humanoid rig (not generic) and I'm using Unity 2019.3.
    and if it helps for anything, I had the same problem way back in Unity 5.6.

    Thank you!
     
    Last edited: Mar 4, 2021
  2. Amuwaru

    Amuwaru

    Joined:
    Dec 17, 2019
    Posts:
    16
    Anyone...?
     
  3. papathor

    papathor

    Joined:
    Oct 8, 2012
    Posts:
    41
    I'm having the same problem on the same version of Unity. I think it might be a bug in Unity, but someone with deeper knowledge into Mecanim would have to confirm.
     
  4. Partel-Lang

    Partel-Lang

    Joined:
    Jan 2, 2013
    Posts:
    2,556
    Looks like in 2019.3 pivotWeight returns 0.5 when you disable "Apply Root Motion". In 2017LTS it works either way, haven't checked other versions.
     
  5. Amuwaru

    Amuwaru

    Joined:
    Dec 17, 2019
    Posts:
    16
    Is this a bug or intended functionality?

    Enabling "Apply Root Motion" does make it return something different than 0.5f in 2019.3, but I don't want to have my character move via root motion when I manage that through code.
     
    Last edited: Jun 22, 2020
  6. Amuwaru

    Amuwaru

    Joined:
    Dec 17, 2019
    Posts:
    16
    I downloaded 2017 LTS and I can confirm that Animator.pivotWeight works there without enabling root motion.

    I tested in 2018 LTS and 2019 LTS too but it doesn't work if root motion isn't enabled.
     
  7. Amuwaru

    Amuwaru

    Joined:
    Dec 17, 2019
    Posts:
    16
    As far as I'm concerned, there's no reason for animator.pivotWeight to work differently than it does in 2017 LTS when Root Motion is disabled.

    I don't know if this is a bug, but if it's by design, I suggest they add it back as an option; like a checkbox below "Apply Root Motion" that it's called "Legacy Pivot Weight" or something of the same nature.

    It's infinitely times better to write a 2-line code to figure out which foot is planted rather than having to manually go through every animation modifying their curves.

    I think I'm going to wait for a couple days, and then report this as a bug to see if I get a definitive answer whether it is or not; seeing that more people have had this problem for a big while but nobody knows how or why this doesn't work the way we expect it to work.
     
    Last edited: Aug 31, 2020
    the_0dium likes this.
  8. BEST-Thanawat

    BEST-Thanawat

    Joined:
    Apr 14, 2020
    Posts:
    7
    After trying to figure it out, I finally found that the Root Motion Node must be set to None. So now I can use animator.PivotWeight to get the pivot weight on the feet.

    Before that, I set the Root Motion Node to be Root then animator.PivotWeight always return at 0.5.

    rootmotion.jpg
     
  9. HuginnRaven

    HuginnRaven

    Joined:
    Dec 20, 2015
    Posts:
    33
    I've done this, and it still only returns 0.5, anyone have any idea?
     
  10. Amuwaru

    Amuwaru

    Joined:
    Dec 17, 2019
    Posts:
    16
    Interesting, all my animations already had this property set to "None".
    Like HuginnRaven says, this still returns 0.5f.
     
  11. BEST-Thanawat

    BEST-Thanawat

    Joined:
    Apr 14, 2020
    Posts:
    7
    After reading your reply, I thought that It depends on the Animation that you used.
    For the testing purpose, I just now changed the Animation to another one(from Asset Store) and set Root Motion Node to Root, the value returns correctly but before that, I used the old one.

    Maybe not related to the Root Motion Node. Just forget about it.

    Untitled.jpg
     
  12. Amuwaru

    Amuwaru

    Joined:
    Dec 17, 2019
    Posts:
    16
    I don't think this has anything to do with the Root Motion Node property.
    I tried changing it to multiple things and nothing really changes about this issue.

    pivotWeight only gets calculated when Apply Root Motion is enabled on the Animator component, but that's not required in 2017 LTS somehow.
     
    Last edited: Feb 26, 2021
  13. Egnech

    Egnech

    Joined:
    Aug 27, 2015
    Posts:
    27
    Run into the same issue, but pivotWeight returns .5f even with Apply Root Motion enabled. I'm using 2020.2.7f1.
     
  14. Egnech

    Egnech

    Joined:
    Aug 27, 2015
    Posts:
    27
    I found that is has something to do with the Root Motion Node, as Thanawat-BEST mentioned. If I simply disable the Motion Node - Animator.pivotWeight starts working as expected. In my case it didn't really help cause I need Root Motion Node to be imported from animations, and not generated by engine.
     
  15. hocboibonmua

    hocboibonmua

    Joined:
    Mar 16, 2021
    Posts:
    1
  16. BEST-Thanawat

    BEST-Thanawat

    Joined:
    Apr 14, 2020
    Posts:
    7
    It depends on the animation as well. You could try other animation sets.
    In some animations, changing the Root Motion Node does not help to get pivotWeight.
     
    trombonaut and Egnech like this.
  17. altair2020

    altair2020

    Joined:
    Mar 6, 2011
    Posts:
    48
    2021.3.3f1.180 - returns 0.5f with root set or root set to none ?
    2021.3.4f1.xxx - returns 0.5f with root set or root set to none ?

    Has anyone figured this out? Do you have to be using root motion ?
     
    Last edited: Jun 23, 2022
  18. Zultron

    Zultron

    Joined:
    Dec 26, 2012
    Posts:
    59
    Confirm this worked
     
  19. Zultron

    Zultron

    Joined:
    Dec 26, 2012
    Posts:
    59
    Problem is this workaround breaks root motion animation. best way is to use then Ik to do check