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.
The following script is attached to the tip of each limb to construct the overall rig at runtime:
using UnityEngine;
using UnityEngine.Animations.Rigging;
public class Limb : MonoBehaviour
{
[SerializeField] private Transform rig;
private void Awake()
{
//Transform limb = new GameObject("Limb").transform; // Doesn't work...
Transform limb = new GameObject("Limb_" + gameObject.GetInstanceID()).transform; // Works?
limb.parent = rig;
Transform target = new GameObject("Target").transform;
target.parent = limb;
TwoBoneIKConstraint tb = limb.gameObject.AddComponent<TwoBoneIKConstraint>();
tb.Reset();
tb.data.tip = transform;
tb.data.mid = transform.parent;
tb.data.root = transform.parent.parent;
tb.data.target = target;
}
}
The rig is then rebuilt using the following code snippet in a separate class:
rigBuilder.Build();
animator.Rebind();