↧
Answer by SimTex
Use reflection. Component new_component = gameObject.AddComponent(old_component.GetType()); foreach (FieldInfo f in old_component.GetType().GetFields()) { f.SetValue(new_component,...
View ArticleAnswer by Ranza
There's also a general solution for this problem: http://unitydevs.com/item/copypaste-component/
View ArticleAnswer by DR9885
To add to that Reflection suggestion, if you are using private serialized variables, like me, you may want something more like this... foreach (FieldInfo info in...
View ArticleAnswer by Eran-Yaacobi
A better approach would be to use UnityEditorInternal namespace: UnityEditorInternal.ComponentUtility.CopyComponent(componentToCopy);...
View Article