@@ -287,21 +287,31 @@ private static void CopyComponents(GameObject from, GameObject to){
287
287
if ( success ) {
288
288
// if to already has this component, then copy the values over
289
289
var toComponent = to . GetComponent ( components [ i ] . GetType ( ) ) ;
290
- if ( toComponent != null ) {
291
- // don't want to copy MeshFilter because then we will replace the
292
- // exported mesh with the old mesh
293
- if ( ! ( toComponent is MeshFilter ) ) {
294
- if ( toComponent is SkinnedMeshRenderer ) {
295
- var skinnedMesh = toComponent as SkinnedMeshRenderer ;
296
- var sharedMesh = skinnedMesh . sharedMesh ;
297
- success = UnityEditorInternal . ComponentUtility . PasteComponentValues ( toComponent ) ;
298
- skinnedMesh . sharedMesh = sharedMesh ;
299
- } else {
300
- success = UnityEditorInternal . ComponentUtility . PasteComponentValues ( toComponent ) ;
301
- }
302
- }
303
- } else {
290
+ if ( toComponent == null ) {
304
291
success = UnityEditorInternal . ComponentUtility . PasteComponentAsNew ( to ) ;
292
+ } else {
293
+ // Don't want to copy MeshFilter because then we will replace the
294
+ // exported mesh with the old mesh.
295
+ if ( toComponent is MeshFilter ) {
296
+ continue ;
297
+ }
298
+ // Don't want to copy materials over either in case the materials are
299
+ // embedded in another model.
300
+ else if ( toComponent is SkinnedMeshRenderer ) {
301
+ var skinnedMesh = toComponent as SkinnedMeshRenderer ;
302
+ var sharedMesh = skinnedMesh . sharedMesh ;
303
+ var sharedMats = skinnedMesh . sharedMaterials ;
304
+ success = UnityEditorInternal . ComponentUtility . PasteComponentValues ( toComponent ) ;
305
+ skinnedMesh . sharedMesh = sharedMesh ;
306
+ skinnedMesh . sharedMaterials = sharedMats ;
307
+ } else if ( toComponent is Renderer ) {
308
+ var renderer = toComponent as Renderer ;
309
+ var sharedMats = renderer . sharedMaterials ;
310
+ success = UnityEditorInternal . ComponentUtility . PasteComponentValues ( toComponent ) ;
311
+ renderer . sharedMaterials = sharedMats ;
312
+ } else {
313
+ success = UnityEditorInternal . ComponentUtility . PasteComponentValues ( toComponent ) ;
314
+ }
305
315
}
306
316
}
307
317
if ( ! success ) {
0 commit comments