Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

Animation Operate IK Target in Worldspace

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

  1. keenanwoodall

    keenanwoodall

    Joined:
    May 30, 2014
    Posts:
    580
    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

    simonbz

    Unity Technologies

    Joined:
    Sep 28, 2015
    Posts:
    141
    Hi,

    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.
unityunity