I’m using UMA so my capsulcollider radius, height and centre are generated at runtime but I need to move the collider up to my parent object. I’m using the following code which I got from this forum but it doesn’t copy the values, only adds the component.
Component CopyComponent(Component original, GameObject destination)
{
System.Type type = original.GetType();
Component copy = destination.AddComponent(type);
// Copied fields can be restricted with BindingFlags
System.Reflection.FieldInfo[] fields = type.GetFields();
foreach (System.Reflection.FieldInfo field in fields)
{
Debug.Log(fields.ToString());
field.SetValue(copy, field.GetValue(original));
}
return copy;
}
I use it like this:
CopyComponent(umaData.gameObject.GetComponent(), umaData.gameObject.transform.parent.parent.parent.gameObject);
Why aren’t the values being copied?