Hi,
I’ve been working on a development tool for copying animation rigging constraints from one empty to another, finding components that inherit from IRigConstraint. It doesn’t print any errors and adds the component, but PropertyInfo.SetValue() isn’t actually changing the data of the component for some reason. I don’t know if this is an issue with the animation rigging package since it is in early release, or if I’m doing something wrong. This code reproduces the effect:
public void CopyConstraint (GameObject target)
{
GameObject bone = transform.gameObject;
IRigConstraint copyFrom = target.GetComponent<IRigConstraint>();
if (copyFrom != null)
{
IRigConstraint copyTo = (IRigConstraint)bone.AddComponent(copyFrom.GetType());
PropertyInfo[] properties = copyTo.data.GetType().GetProperties();
foreach (PropertyInfo pi in properties)
{
var data = pi.GetValue(copyFrom.data);
pi.SetValue(copyTo.data, data);
}
}
}
Right now this function just runs from a button pressed in a custom inspector.
Am I doing something wrong here? Is this an error with the preview package and, if so, is there a workaround? It needs to work for all constraint types and, ideally, for custom constraints as well so I want to keep it as general as possible
Thanks in advance,
Adam