@@ -172,13 +172,30 @@ private static void CopyComponentsRecursive(GameObject from, GameObject to){
172
172
private static void CopyComponents ( GameObject from , GameObject to ) {
173
173
var components = from . GetComponents < Component > ( ) ;
174
174
for ( int i = 0 ; i < components . Length ; i ++ ) {
175
- // if to already has this component, then skip it
176
- if ( components [ i ] == null || to . GetComponent ( components [ i ] . GetType ( ) ) != null ) {
175
+ if ( components [ i ] == null ) {
177
176
continue ;
178
177
}
178
+
179
179
bool success = UnityEditorInternal . ComponentUtility . CopyComponent ( components [ i ] ) ;
180
180
if ( success ) {
181
- success = UnityEditorInternal . ComponentUtility . PasteComponentAsNew ( to ) ;
181
+ // if to already has this component, then copy the values over
182
+ var toComponent = to . GetComponent ( components [ i ] . GetType ( ) ) ;
183
+ if ( toComponent != null ) {
184
+ // don't want to copy MeshFilter because then we will replace the
185
+ // exported mesh with the old mesh
186
+ if ( ! ( toComponent is MeshFilter ) ) {
187
+ if ( toComponent is SkinnedMeshRenderer ) {
188
+ var skinnedMesh = toComponent as SkinnedMeshRenderer ;
189
+ var sharedMesh = skinnedMesh . sharedMesh ;
190
+ success = UnityEditorInternal . ComponentUtility . PasteComponentValues ( toComponent ) ;
191
+ skinnedMesh . sharedMesh = sharedMesh ;
192
+ } else {
193
+ success = UnityEditorInternal . ComponentUtility . PasteComponentValues ( toComponent ) ;
194
+ }
195
+ }
196
+ } else {
197
+ success = UnityEditorInternal . ComponentUtility . PasteComponentAsNew ( to ) ;
198
+ }
182
199
}
183
200
if ( ! success ) {
184
201
Debug . LogWarning ( string . Format ( "Warning: Failed to copy component {0} from {1} to {2}" ,
0 commit comments