@@ -291,29 +291,34 @@ private static void CopyComponents(GameObject from, GameObject to){
291
291
var toComponent = originalComponents [ j ] ;
292
292
// If component already exists, paste values.
293
293
if ( toComponent . GetType ( ) == components [ i ] . GetType ( ) ) {
294
+ // we have found the component we are looking for, remove it so
295
+ // we don't try to copy to it again
296
+ originalComponents . RemoveAt ( j ) ;
297
+ foundComponentOfType = true ;
298
+
294
299
// Don't want to copy MeshFilter because then we will replace the
295
300
// exported mesh with the old mesh.
296
- if ( ! ( toComponent is MeshFilter ) ) {
297
- // Don't want to copy materials over in case the materials are
298
- // embedded in another model.
299
- if ( toComponent is SkinnedMeshRenderer ) {
300
- var skinnedMesh = toComponent as SkinnedMeshRenderer ;
301
- var sharedMesh = skinnedMesh . sharedMesh ;
302
- var sharedMats = skinnedMesh . sharedMaterials ;
303
- success = UnityEditorInternal . ComponentUtility . PasteComponentValues ( toComponent ) ;
304
- skinnedMesh . sharedMesh = sharedMesh ;
305
- skinnedMesh . sharedMaterials = sharedMats ;
306
- } else if ( toComponent is Renderer ) {
307
- var renderer = toComponent as Renderer ;
308
- var sharedMats = renderer . sharedMaterials ;
309
- success = UnityEditorInternal . ComponentUtility . PasteComponentValues ( toComponent ) ;
310
- renderer . sharedMaterials = sharedMats ;
311
- } else {
312
- success = UnityEditorInternal . ComponentUtility . PasteComponentValues ( toComponent ) ;
313
- }
301
+ if ( toComponent is MeshFilter ) {
302
+ break ;
303
+ }
304
+
305
+ // Don't want to copy materials over in case the materials are
306
+ // embedded in another model.
307
+ if ( toComponent is SkinnedMeshRenderer ) {
308
+ var skinnedMesh = toComponent as SkinnedMeshRenderer ;
309
+ var sharedMesh = skinnedMesh . sharedMesh ;
310
+ var sharedMats = skinnedMesh . sharedMaterials ;
311
+ success = UnityEditorInternal . ComponentUtility . PasteComponentValues ( toComponent ) ;
312
+ skinnedMesh . sharedMesh = sharedMesh ;
313
+ skinnedMesh . sharedMaterials = sharedMats ;
314
+ } else if ( toComponent is Renderer ) {
315
+ var renderer = toComponent as Renderer ;
316
+ var sharedMats = renderer . sharedMaterials ;
317
+ success = UnityEditorInternal . ComponentUtility . PasteComponentValues ( toComponent ) ;
318
+ renderer . sharedMaterials = sharedMats ;
319
+ } else {
320
+ success = UnityEditorInternal . ComponentUtility . PasteComponentValues ( toComponent ) ;
314
321
}
315
- originalComponents . RemoveAt ( j ) ;
316
- foundComponentOfType = true ;
317
322
break ;
318
323
}
319
324
}
0 commit comments