Search Unity

Resolved Rigs can't have the same name?

Discussion in 'Animation Rigging' started by daniel_lochner, Feb 24, 2021.

  1. daniel_lochner

    daniel_lochner

    Joined:
    Jun 9, 2016
    Posts:
    173
    Hi there,

    Not sure if this is a bug or not, since it isn't mentioned in the documentation anywhere, but are you allowed to use the same name for game objects within the same rig?

    The only difference between the following two screenshots is that rigs in the second have differing names.
    upload_2021-2-24_19-42-49.png
    upload_2021-2-24_19-42-56.png

    The following script is attached to the tip of each limb to construct the overall rig at runtime:
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Animations.Rigging;
    3.  
    4. public class Limb : MonoBehaviour
    5. {
    6.     [SerializeField] private Transform rig;
    7.  
    8.     private void Awake()
    9.     {
    10.         //Transform limb = new GameObject("Limb").transform; // Doesn't work...
    11.         Transform limb = new GameObject("Limb_" + gameObject.GetInstanceID()).transform; // Works?
    12.         limb.parent = rig;
    13.  
    14.         Transform target = new GameObject("Target").transform;
    15.         target.parent = limb;
    16.  
    17.         TwoBoneIKConstraint tb = limb.gameObject.AddComponent<TwoBoneIKConstraint>();
    18.         tb.Reset();
    19.         tb.data.tip = transform;
    20.         tb.data.mid = transform.parent;
    21.         tb.data.root = transform.parent.parent;
    22.         tb.data.target = target;
    23.     }
    24. }
    The rig is then rebuilt using the following code snippet in a separate class:
    Code (CSharp):
    1. rigBuilder.Build();
    2. animator.Rebind();
     
  2. simonbz

    simonbz

    Unity Technologies

    Joined:
    Sep 28, 2015
    Posts:
    295
    Hi,

    Seeing your issue, I'm guessing your rig is imported as humanoid?

    Bone names in a Humanoid character need to be unique. Because of this limitation, your animation rigging hierarchy must also have unique names.
     
  3. daniel_lochner

    daniel_lochner

    Joined:
    Jun 9, 2016
    Posts:
    173
    Hi Simon, thanks for your response! The rig is actually imported as generic. Also, I just moved over to a test project to figure out what was happening, so the rig I'm actually working with is also generic (procedurally generated at runtime).
    upload_2021-2-26_8-22-7.png
     
  4. simonbz

    simonbz

    Unity Technologies

    Joined:
    Sep 28, 2015
    Posts:
    295
    Sorry for the delay, I can't be active on the forum as I once used to be.

    Right, so I missed that in your example the first time you posted it, but the way you built your hierarchy will not work. The animation bindings are name based, so while you can have duplicate names in your hierarchy, your path however must be unique.

    So this will work:

    MyRoot
    MyRig1
    MyLimb​
    MyRig2
    MyLimb​

    While this will not:

    MyRoot
    MyRig
    MyLimb
    MyLimb​