Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at id.unity.com during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.


    Read our full announcement for more information and let us know if you have any questions.

Question Adding IK Rig to character at runtime

Discussion in 'Animation Rigging' started by DDobyns, Sep 12, 2020.

  1. DDobyns

    DDobyns

    Joined:
    Jan 28, 2018
    Posts:
    7
    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:

    1. parent the arm gameobject to my rig's shoulder gameobject
    2. parent the new arm's rig gameobject alongside existing IK rigs
    3. add this new rig to the character's RigBuilder
    4. 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 https://forum.unity.com/threads/generating-rig-at-runtime.935090/ but can't seem to get this working.
     
  2. DDobyns

    DDobyns

    Joined:
    Jan 28, 2018
    Posts:
    7
    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 :)
     
  3. simonbz

    simonbz

    Unity Technologies

    Joined:
    Sep 28, 2015
    Posts:
    295
    Hi,

    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.