Operate IK Target in Worldspace

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.

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.

2 Likes