Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Operate IK Target in Worldspace

Discussion in 'Animation Rigging' started by keenanwoodall, Nov 17, 2019.

  1. keenanwoodall


    May 30, 2014
    I'm trying to create a procedurally animated character. The position/rotation of the character is determined by the feet, so moving the feet moves the character.

    The easiest way to control the IK targets would be for them to be in the root of the scene so that when the character is moved the IK targets aren't affected. (When using Final IK I just added a small utility script that unparented its game object on start.)

    The issue is that it doesn't look like you can change the parent of IK targets at runtime. This means I can't keep the IK targets in the character prefab and just unparent them at runtime. I don't want the targets to exist outside the character prefab in edit-mode since I'll have to create and position new targets every time I make a new instance of the character.

    I could create another set of transforms for each target, unparent them at runtime, and then constantly convert their position/rotation to be local to the actual target and then assign those position/rotations back to the actual IK targets, but if there's already a way to handle worldspace IK targets I'd love to know about it.

    [edit] It appears that setting the targets parent to null in Awake works, but I'm still not sure how to change the parent once the Animator has been initialized.
    Last edited: Nov 18, 2019
  2. simonbz


    Unity Technologies

    Sep 28, 2015

    I'll try and shed some more light on how Animation Rigging uses data in the RigConstraint components. When initialized, the RigBuilder collects all constraints in all children Rigs to create a PlayableGraph with AnimationScriptPlayable nodes that refer to the Transforms that were set in the initial Rig setup. The resulting transform handles are references in the AnimationStream rather than Transform themselves to ensure that PlayableGraph execution is as optimal as possible.

    To make sure that RigBuilder is initialized at the right time, reparent your Transform component first, then enable the RigBuilder afterwards. Otherwise, you can call `Build()` on the RigBuilder after you reparent Transform to rebuild the PlayableGraph with the proper references.
    keenanwoodall and florianhanke like this.