Quantcast
Channel: Answers for "Editor Wizard: Copy Existing Components to Another GameObject"
Browsing latest articles
Browse All 8 View Live

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 Article


Answer by Ranza

There's also a general solution for this problem: http://unitydevs.com/item/copypaste-component/

View Article


Answer 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 Article

Answer by Eran-Yaacobi

A better approach would be to use UnityEditorInternal namespace: UnityEditorInternal.ComponentUtility.CopyComponent(componentToCopy);...

View Article
Browsing latest articles
Browse All 8 View Live