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