I have a character whose limbs are IK controlled (using Unity Animation Rigging rigs and constraints), and I’m trying to attach/detach limbs at runtime. Here is my “attach an arm to this character” example:
parent the arm gameobject to my rig’s shoulder gameobject
parent the new arm’s rig gameobject alongside existing IK rigs
add this new rig to the character’s RigBuilder
call Rebuild() on the RigBuilder
What I’m seeing is that the components all appear to be hooked up properly, but the two bone constraint of the new arm isn’t doing anything.
What steps are required to actually add a new rig to a character at runtime like this? I’ve read similar threads like Generating Rig at runtime but can’t seem to get this working.
One alternative solution might be to have attachable IK objects like limbs be separate Game Objects that get connected to the character using constraints - e.g., an Arm game object is “attached” using a multi-position constraint to the character’s shoulder and stays a separate object rather than being parented to the character.
It seems hacky but I guess that might work? The last alternative I might try if I’m unable to solve the original issue is to rebuild the entire GameObject hierarchy when modifying it’s anatomy, which would probably ensure the right initialization always happens, but that seems like a horrible workaround - hopefully there’s a way to add Rigs and Constraints at runtime and I’m just missing some small step
Did you make sure to also rebind the animator when changing your rig?
Calling Animator.enabled = false and Animator.enabled = true around the changes you’re making to your rigs will ensure the bindings are properly recalculated.
Also, are there any errors in the console when you’re doing that? This may help pinpoint what game objects are not resolved.