Search Unity

Question How to tell animation rigging to use a specific bone hierarchy and not search all bones?

Discussion in 'Animation Rigging' started by altepTest, Jan 25, 2021.

  1. altepTest

    altepTest

    Joined:
    Jul 5, 2012
    Posts:
    1,118
    I have a character with bones and avatar and the animator component. I've set up Animation Rigging and it works perfectly.

    No problem there.

    Now visualize this, the gameobject (the character) where the Animator and the Rig Builder is attached is the main parent. Under, there are various other children game objects and one of these attached trees is the tree with the bones that the character uses.

    Fine

    Now I've attached to the character a second rig that happens to have the same bones name as the parent.

    But animation rigging doesn't work anymore, for some reason it searches for bones in all children of the gameobject character and it gets confused because it finds two bones with the same name

    In the "Anim Rig Init Constrains" I've specifically set up the hip and hands and legs to use the correct bones yet it ignores these direct reference to the bones and tries to access ALSO the duplicate rig I've added under the top gameobject (character).

    How it should work:

    Set up Animation rigging for a particular bones tree.

    Then Animation Rigging should access and change only that particular bone tree.

    How it works now:

    Even if you have specifically said what hip, hands legs bones, Animation Rigging should use, it searches all the childrens and tries to set anything that matches those bones names. If you have children that have the same name it will mess everything up.


    A few of the errors it throws (there 1k+ of them):

    Code (CSharp):
    1. Ambiguous Transform found in hierarchy for human bone. Transform name mapped to a human bone must be unique.
    2. Could not resolve 'AnimationRig/HipRig/Constrain_Hip' because the avatar is invalid. Please assign a valid Avatar or create one with AvatarBuilder.
    3. System.InvalidOperationException: The TransformStreamHandle cannot be resolved.
    4. Thrown from job: UnityEngine.Animations.Rigging.RigSyncSceneToStreamJob
    5.  
    Question.

    How to I force Animation Rigging to use/access/update/change only the specific bone rig hierarchy that I've set up for the system?

    If something not clear please let me know to explain better
     
    JerryZ19 likes this.
  2. altepTest

    altepTest

    Joined:
    Jul 5, 2012
    Posts:
    1,118
    This happens only if the duplicate rig hierarchy is added before hitting the Play button. If I start the game and I add the duplicate hip hierarchy during gameplay there are no issues everything works correctly. So maybe on Awake or something the Animation Rig builds a bone structure reference and it messes up because of duplicated children game objects. But it there are no duplicates and the reference is created correctly it doesn't care about new objects added during gameplay.

    Damn I wish I now how to change these scripts :( to force it to see only the correct rig all the time
     
    Maxim likes this.
  3. altepTest

    altepTest

    Joined:
    Jul 5, 2012
    Posts:
    1,118
    In the RigUtils.cs it appears it searches for IsChildOf(animator.transform) so obviously it will find duplicates, how to force it to search only on the rig that the animation rig was set up for?
     
  4. simonbz

    simonbz

    Unity Technologies

    Joined:
    Sep 28, 2015
    Posts:
    295
    Hi, like it's said in the error message:
    "Ambiguous Transform found in hierarchy for human bone. Transform name mapped to a human bone must be unique."

    Humanoid characters require unique bone names to work.
    You'll either need to:
    - Rename bones in your nested hierarchy to distinguish it from the base humanoid hierarchy.
    - Convert your rig to generic where you'll be able to work with duplicates.
     
  5. altepTest

    altepTest

    Joined:
    Jul 5, 2012
    Posts:
    1,118
    Is not an issue with the unique bones, is that when animation rigging is doing the initial setup it doesn't perform a precise search for the bones to build a correct hierarchy, it searches all the children of the top object that have the Animator component attached.

    please check this image for a visual explanation animationriggim.jpg
     
  6. altepTest

    altepTest

    Joined:
    Jul 5, 2012
    Posts:
    1,118
    As an update to this issue, while unity staff ignores user feedback unreal created a fully working rig system that is like comparing a space ship with a wooden wheel cart. And the wooden cart is this animation rig.

    I've managed in unity to create a simple script that do exactly what you are saying is not possible. Only issue it had is that unity created this rig system to recursively check ALL bones in a humanoid prefab, instead of checking only the bones that the humanoid has.

    Lazy implementation where it just check everything included in the prefab. Like really?

    Meanwhile I've abandoned unity for all these small problems and I've checked unreal. There is nothing to compare, this system you have here is child play.

    They also have one simple blueprint node to tell the engine to set a master skeleton that other figures with same skeleton NAMES can use as reference.

    Instead of learning how to do it in unity, and I've invested months to learn about all this advanced stuff, instead it was a matter of one minute in an engine where they know what they are doing. One single node.

    If this message doesn't get deleted and if you read this in the future and you want to create a game that needs a rig don't do it like me. Close this forum, uninstall unity, open youtube and check unreal control rig. Don't lose two years like I've did.
     
    funkyCoty likes this.
  7. zwwdm

    zwwdm

    Joined:
    Nov 5, 2013
    Posts:
    2
    Is this problem not solved? This is a hard injury
     
  8. Beloudest

    Beloudest

    Joined:
    Mar 13, 2015
    Posts:
    247
    I got around this issue by moving the child objects with same bone names outside of the parent you are trying to rig. Enable the Rig Builder after to build it, then copy the child bones/armature back into the parent after and you avoid the errors. So far everything is working as expected.
     
    MUGIK likes this.
  9. MUGIK

    MUGIK

    Joined:
    Jul 2, 2015
    Posts:
    481
    In my case it was also required to call Animator.Update(0); before parenting second rig back.

    So the full algorithm:

    Code (CSharp):
    1. void Awake()
    2. {
    3.   var parent = childRig.parent; // save parent
    4.   childRig.SetParent(null); // unparent rig
    5.   GetComponent<RigBuilder>().enabled = true;
    6.   GetComponent<Animator>().Update(0.0f); // in theory 0.0f should result in no pos/rot change of the animated transforms, so parenting rig back won't change local(relative) position.
    7.   childRig.SetParent(parent); // parent rig back where it was
    8. }
     
    Last edited: Jan 31, 2024
  10. Beloudest

    Beloudest

    Joined:
    Mar 13, 2015
    Posts:
    247
    Interesting. I had a similar issue but just set the child objects to the local position Vector3.zero after copying it back into my RigidBodies rig. I think the next step is optimise all my Bone rigs into a combined mesh at runtime so there is less skinned renderers.