Skip to content

Commit 6879e36

Browse files
committed
don't copy materials in renderer components
1 parent b4fb717 commit 6879e36

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

Assets/FbxExporters/Editor/ConvertToModel.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,14 +288,23 @@ private static void CopyComponents(GameObject from, GameObject to){
288288
// if to already has this component, then copy the values over
289289
var toComponent = to.GetComponent (components [i].GetType ());
290290
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.
293295
if (!(toComponent is MeshFilter)) {
294296
if (toComponent is SkinnedMeshRenderer) {
295297
var skinnedMesh = toComponent as SkinnedMeshRenderer;
296298
var sharedMesh = skinnedMesh.sharedMesh;
299+
var sharedMats = skinnedMesh.sharedMaterials;
297300
success = UnityEditorInternal.ComponentUtility.PasteComponentValues (toComponent);
298301
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;
299308
} else {
300309
success = UnityEditorInternal.ComponentUtility.PasteComponentValues (toComponent);
301310
}

0 commit comments

Comments
 (0)