Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bug Constraint ignored when moving root bone?

Discussion in 'Animation Rigging' started by daniel_lochner, Apr 21, 2021.

  1. daniel_lochner

    daniel_lochner

    Joined:
    Jun 9, 2016
    Posts:
    170
    Hi there,

    When I try to move my character's hips in preview mode, the rig behaves correctly – constraining its foot to the floor (as a result of the
    Two-Bone IK
    constraint). However when I do the same in play-mode, it instead adjusts the default offset position?

    Here's a video demonstrating the issue (please note that the red circle shows the desired behaviour):


    Thanks in advance for your time!
     
    Last edited: May 6, 2021
  2. daniel_lochner

    daniel_lochner

    Joined:
    Jun 9, 2016
    Posts:
    170
    I just encountered another case (rotating the hips) which again functions correctly in preview mode, but not play mode:
     
  3. daniel_lochner

    daniel_lochner

    Joined:
    Jun 9, 2016
    Posts:
    170
    Still have this issue unfortunately. Is it a bug, or am I misunderstanding something? Thanks! :)
     
  4. Yandalf

    Yandalf

    Joined:
    Feb 11, 2014
    Posts:
    491
    This is a misunderstanding on your part.
    What's basically happening here is that your IK Target moves along with the root bone during play mode, because the target is a child of the root. During preview the IK Target apparently doesn't get updated properly, making it look like what you actually want to happen as you move the root around.
    A simple script that updates the IK Target's position to the same place each update will counteract this, which you can then expand for easier coding of IKs later, something like:
    Code (CSharp):
    1. public Vector3 worldPosition;
    2. public Quaternion worldRotation;
    3.  
    4. Update()
    5. {
    6.     transform.position = worldPosition;
    7.     transform.rotation = worldRotation;
    8. }
    then whenever you want to move your IK Target, you just change the worldPosition and Rotation variables in that script.
     
    JamesNunesRoundtable likes this.
  5. daniel_lochner

    daniel_lochner

    Joined:
    Jun 9, 2016
    Posts:
    170
    Hey Yandalf, thanks for the response!
    The target is a child of the rig (and character root, "Swat"), but not the root bone ("swat:Hips")? Why would it then move along with the root bone ("swat:Hips") during play mode?

    If I move the target outside of the rig, the problem still persists. In the screenshot below (taken during play-mode), the character should be bending his knee?
    Bug.png
     
    Last edited: May 6, 2021
  6. Yandalf

    Yandalf

    Joined:
    Feb 11, 2014
    Posts:
    491
    Definitely don't move the target outside of the hierarchy, that's gonna cause only more issues.
    I just realised that you indeed shouldn't have trouble like this. Can you make sure the Rig has been referenced in the Builder during playmode and that all rigweights have been set to 1?
     
  7. daniel_lochner

    daniel_lochner

    Joined:
    Jun 9, 2016
    Posts:
    170
    Yes, I can confirm all weights are set to 1, and that the rig has been referenced in the
    RigBuilder
    component.

    I've added an additional video to show the target outside of the hierarchy (not sure why this is not advisable?) and how moving the root bone behaves differently to moving the character root:
     
    Last edited: May 6, 2021
  8. daniel_lochner

    daniel_lochner

    Joined:
    Jun 9, 2016
    Posts:
    170
    Do you suspect this could be a bug?
     
  9. simonbz

    simonbz

    Unity Technologies

    Joined:
    Sep 28, 2015
    Posts:
    295
    Did you try adding a `RigTransform` component on the bone you want to affect your hierarchy?

    If a transform is not animated or directly used by a constraint, then it remains static in the AnimationStream. The RigTransform component allows to specify game objects you want to consider in the AnimationStream.

    link to documentation
     
    daniel_lochner likes this.
  10. Yandalf

    Yandalf

    Joined:
    Feb 11, 2014
    Posts:
    491
    Simon, I'd think that wouldn't be the issue here (at least in the initial setup) since the Target GO is referenced straight in the Two-Bone IK object and originally parented to the Rig hierarchy.
     
  11. simonbz

    simonbz

    Unity Technologies

    Joined:
    Sep 28, 2015
    Posts:
    295
    The TwoBoneIK target is parented to the Rig hierarchy, but the FK is still parented to the hips in this instance. For TwoBoneIK, the constraint will read the world position from the stream for root, mid and tip bones and this position will not be updated as you would expect when modified from gameplay code (or in the scene view like it is now) unless you add a RigTransform to the GameObject.
     
  12. Yandalf

    Yandalf

    Joined:
    Feb 11, 2014
    Posts:
    491
    Oh yeah, you're totally right! I wasn't paying attention to how they're influencing the hips.
     
  13. daniel_lochner

    daniel_lochner

    Joined:
    Jun 9, 2016
    Posts:
    170
    Fantastic, it works! Thanks so much @simonbz! :D And thanks for your help as well @Yandalf, I really do appreciate it!
     
  14. MathDantasTav

    MathDantasTav

    Joined:
    Jul 21, 2018
    Posts:
    5
    just realized that the hip needs to be on the top of the hierarchy, anything above it, will just move along instead of staying put. Don't know if this is the same issue as you guys
    upload_2022-11-7_18-21-51.png
     
  15. fleity

    fleity

    Joined:
    Oct 13, 2015
    Posts:
    337
    In order to generalize the previous post a bit:
    From my expierence so far, the sibling index / order in the hierarchy for AnimRigs does matter.

    Therefore hips first, next look at rigs, then legs, then arms, then anything else usually works for me.
    This is tricky though for quadruped rigs, in which you want to move the body according to the legs, in those cases it's first legs obviously.