<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="http://wiki.unity3d.com/skins/common/feed.css?303"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://wiki.unity3d.com/index.php?title=CopyComponents&amp;feed=atom&amp;action=history</id>
		<title>CopyComponents - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://wiki.unity3d.com/index.php?title=CopyComponents&amp;feed=atom&amp;action=history"/>
		<link rel="alternate" type="text/html" href="http://wiki.unity3d.com/index.php?title=CopyComponents&amp;action=history"/>
		<updated>2013-05-20T17:58:39Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.19.1</generator>

	<entry>
		<id>http://wiki.unity3d.com/index.php?title=CopyComponents&amp;diff=13985&amp;oldid=prev</id>
		<title>Yuriks: Fixed file name</title>
		<link rel="alternate" type="text/html" href="http://wiki.unity3d.com/index.php?title=CopyComponents&amp;diff=13985&amp;oldid=prev"/>
				<updated>2012-02-06T21:39:00Z</updated>
		
		<summary type="html">&lt;p&gt;Fixed file name&lt;/p&gt;
&lt;table class='diff diff-contentalign-left'&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
			&lt;tr valign='top'&gt;
			&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;← Older revision&lt;/td&gt;
			&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 21:39, 6 February 2012&lt;/td&gt;
			&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 8:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 8:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Place this script in ''Assets/Editor'' and select the option in the tools menu. Specify the source and destination GameObject hierarchies, as well as an additional prefix on the destination objects. GameObjects in the source without a match in the destination will be skipped and a warning printed. '''NOTE:''' Save your scene before running this script. The functions used tend to mess up Unity's internal data structures and make it crash ocasionally.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Place this script in ''Assets/Editor'' and select the option in the tools menu. Specify the source and destination GameObject hierarchies, as well as an additional prefix on the destination objects. GameObjects in the source without a match in the destination will be skipped and a warning printed. '''NOTE:''' Save your scene before running this script. The functions used tend to mess up Unity's internal data structures and make it crash ocasionally.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;==C# - &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;AddComponentRecursively&lt;/del&gt;.&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;js&lt;/del&gt;==&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;==C# - &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;CopyComponents&lt;/ins&gt;.&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;cs&lt;/ins&gt;==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;using UnityEngine;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;using UnityEngine;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;using UnityEditor;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;using UnityEditor;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Yuriks</name></author>	</entry>

	<entry>
		<id>http://wiki.unity3d.com/index.php?title=CopyComponents&amp;diff=13984&amp;oldid=prev</id>
		<title>Yuriks: Added crash warning.</title>
		<link rel="alternate" type="text/html" href="http://wiki.unity3d.com/index.php?title=CopyComponents&amp;diff=13984&amp;oldid=prev"/>
				<updated>2012-02-06T21:38:21Z</updated>
		
		<summary type="html">&lt;p&gt;Added crash warning.&lt;/p&gt;
&lt;table class='diff diff-contentalign-left'&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
			&lt;tr valign='top'&gt;
			&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;← Older revision&lt;/td&gt;
			&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 21:38, 6 February 2012&lt;/td&gt;
			&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 6:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 6:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;==Usage==&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;==Usage==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Place this script in ''Assets/Editor'' and select the option in the tools menu. Specify the source and destination GameObject hierarchies, as well as an additional prefix on the destination objects. GameObjects in the source without a match in the destination will be skipped and a warning printed.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Place this script in ''Assets/Editor'' and select the option in the tools menu. Specify the source and destination GameObject hierarchies, as well as an additional prefix on the destination objects. GameObjects in the source without a match in the destination will be skipped and a warning printed&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;. '''NOTE:''' Save your scene before running this script. The functions used tend to mess up Unity's internal data structures and make it crash ocasionally&lt;/ins&gt;.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;==C# - AddComponentRecursively.js==&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;==C# - AddComponentRecursively.js==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Yuriks</name></author>	</entry>

	<entry>
		<id>http://wiki.unity3d.com/index.php?title=CopyComponents&amp;diff=13983&amp;oldid=prev</id>
		<title>Yuriks: Added initial script.</title>
		<link rel="alternate" type="text/html" href="http://wiki.unity3d.com/index.php?title=CopyComponents&amp;diff=13983&amp;oldid=prev"/>
				<updated>2012-02-06T21:36:11Z</updated>
		
		<summary type="html">&lt;p&gt;Added initial script.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;[[Category: Wizard]]&lt;br /&gt;
[[Category: CSharp]]&lt;br /&gt;
Author: Yuri Kunde Schlesner (yuriks)&lt;br /&gt;
==Description==&lt;br /&gt;
This script matches GameObjects from one hierarchy to the other, and then clones all components, transferring them to the destination.&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
Place this script in ''Assets/Editor'' and select the option in the tools menu. Specify the source and destination GameObject hierarchies, as well as an additional prefix on the destination objects. GameObjects in the source without a match in the destination will be skipped and a warning printed.&lt;br /&gt;
&lt;br /&gt;
==C# - AddComponentRecursively.js==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;using UnityEngine;&lt;br /&gt;
using UnityEditor;&lt;br /&gt;
using System.Collections;&lt;br /&gt;
&lt;br /&gt;
public class CopyComponents : ScriptableWizard {&lt;br /&gt;
	public GameObject source;&lt;br /&gt;
	public GameObject destination;&lt;br /&gt;
	public string namePrefix = &amp;quot;skin_&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
	static GameObject findChildWithName(GameObject go, string name) {&lt;br /&gt;
		foreach (Transform child_transform in go.transform) {&lt;br /&gt;
			GameObject child = child_transform.gameObject;&lt;br /&gt;
&lt;br /&gt;
			if (child.name == name)&lt;br /&gt;
				return child;&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		return null;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	void RecursiveCopy(GameObject src, GameObject dst) {&lt;br /&gt;
		Debug.Log(&amp;quot;Copying from &amp;quot; + src.name + &amp;quot; to &amp;quot; + dst.name);&lt;br /&gt;
&lt;br /&gt;
		Component[] src_components = src.GetComponents(typeof(Component));&lt;br /&gt;
&lt;br /&gt;
		foreach (Component comp in src_components) {&lt;br /&gt;
			if (comp is Transform || comp is Renderer || comp is Animation)&lt;br /&gt;
				continue;&lt;br /&gt;
&lt;br /&gt;
			//Debug.Log(&amp;quot;Adding &amp;quot; + comp.GetType().Name + &amp;quot; to &amp;quot; + dst.name);&lt;br /&gt;
			Component dst_comp = dst.AddComponent(comp.GetType());&lt;br /&gt;
&lt;br /&gt;
			SerializedObject src_ser_obj = new SerializedObject(comp);&lt;br /&gt;
			SerializedObject dst_ser_obj = new SerializedObject(dst_comp);&lt;br /&gt;
			src_ser_obj.Update();&lt;br /&gt;
			dst_ser_obj.Update();&lt;br /&gt;
&lt;br /&gt;
			SerializedProperty ser_prop = src_ser_obj.GetIterator();&lt;br /&gt;
&lt;br /&gt;
			bool enterChildren = true;&lt;br /&gt;
			while (ser_prop.Next(enterChildren)) {&lt;br /&gt;
				enterChildren = true;&lt;br /&gt;
				string path = ser_prop.propertyPath;&lt;br /&gt;
&lt;br /&gt;
				bool skip = false;&lt;br /&gt;
				foreach (string blacklisted_path in propertyBlacklist) {&lt;br /&gt;
					if (path.EndsWith(blacklisted_path)) {&lt;br /&gt;
						skip = true;&lt;br /&gt;
						break;&lt;br /&gt;
					}&lt;br /&gt;
				}&lt;br /&gt;
				if (skip) {&lt;br /&gt;
					enterChildren = false;&lt;br /&gt;
					continue;&lt;br /&gt;
				}&lt;br /&gt;
&lt;br /&gt;
				//Debug.Log(path);&lt;br /&gt;
				SerializedProperty dst_ser_prop = dst_ser_obj.FindProperty(path);&lt;br /&gt;
				AssignSerializedProperty(ser_prop, dst_ser_prop);&lt;br /&gt;
			}&lt;br /&gt;
&lt;br /&gt;
			dst_ser_obj.ApplyModifiedProperties();&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		foreach (Transform child_transform in src.transform) {&lt;br /&gt;
			GameObject child = child_transform.gameObject;&lt;br /&gt;
&lt;br /&gt;
			string dst_object_name = namePrefix + child.name;&lt;br /&gt;
			GameObject dst_object = findChildWithName(dst, dst_object_name);&lt;br /&gt;
&lt;br /&gt;
			if (dst_object == null) {&lt;br /&gt;
				Debug.LogWarning(&amp;quot;Didn't find matching GameObject for &amp;quot; + child.name);&lt;br /&gt;
				continue;&lt;br /&gt;
			}&lt;br /&gt;
&lt;br /&gt;
			RecursiveCopy(child, dst_object);&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	static string[] propertyBlacklist = new string[] {&lt;br /&gt;
		&amp;quot;m_ObjectHideFlags&amp;quot;, &amp;quot;m_PrefabParentObject&amp;quot;, &amp;quot;m_PrefabInternal&amp;quot;, &amp;quot;m_GameObject&amp;quot;, &amp;quot;m_EditorHideFlags&amp;quot;, &amp;quot;m_FileID&amp;quot;, &amp;quot;m_PathID&amp;quot;&lt;br /&gt;
	};&lt;br /&gt;
&lt;br /&gt;
	static void AssignSerializedProperty(SerializedProperty from, SerializedProperty to) {&lt;br /&gt;
		if (from.propertyType != to.propertyType)&lt;br /&gt;
			Debug.LogError(&amp;quot;SerializedPropertys have different types!&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
		switch (from.propertyType) {&lt;br /&gt;
			case SerializedPropertyType.Integer        : to.intValue             = from.intValue;             break;&lt;br /&gt;
			case SerializedPropertyType.Boolean        : to.boolValue            = from.boolValue;            break;&lt;br /&gt;
			case SerializedPropertyType.Float          : to.floatValue           = from.floatValue;           break;&lt;br /&gt;
			case SerializedPropertyType.String         : to.stringValue          = from.stringValue;          break;&lt;br /&gt;
			case SerializedPropertyType.Color          : to.colorValue           = from.colorValue;           break;&lt;br /&gt;
			case SerializedPropertyType.ObjectReference: to.objectReferenceValue = from.objectReferenceValue; break;&lt;br /&gt;
			case SerializedPropertyType.LayerMask      : to.intValue             = from.intValue;             break;&lt;br /&gt;
			case SerializedPropertyType.Enum           : to.enumValueIndex       = from.enumValueIndex;       break;&lt;br /&gt;
			case SerializedPropertyType.Vector2        : to.vector2Value         = from.vector2Value;         break;&lt;br /&gt;
			case SerializedPropertyType.Vector3        : to.vector3Value         = from.vector3Value;         break;&lt;br /&gt;
			case SerializedPropertyType.Rect           : to.rectValue            = from.rectValue;            break;&lt;br /&gt;
			case SerializedPropertyType.ArraySize      : to.intValue             = from.intValue;             break;&lt;br /&gt;
			case SerializedPropertyType.Character      : to.intValue             = from.intValue;             break;&lt;br /&gt;
			case SerializedPropertyType.AnimationCurve : to.animationCurveValue  = from.animationCurveValue;  break;&lt;br /&gt;
			case SerializedPropertyType.Bounds         : to.boundsValue          = from.boundsValue;          break;&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	void OnWizardCreate() {&lt;br /&gt;
		RecursiveCopy(source, destination);&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	[MenuItem(&amp;quot;Tools/Copy Components&amp;quot;)]&lt;br /&gt;
	static void DoCopyComponents() {&lt;br /&gt;
		ScriptableWizard.DisplayWizard&amp;lt;CopyComponents&amp;gt;(&amp;quot;Copy Components&amp;quot;, &amp;quot;Copy&amp;quot;);&lt;br /&gt;
	}&lt;br /&gt;
}&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Yuriks</name></author>	</entry>

	</feed>