Quantcast
Channel: Answers for "Editor Wizard: Copy Existing Components to Another GameObject"
Browsing all 8 articles
Browse latest 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

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 all 8 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>