Skip to content

Commit 40b4454

Browse files
committed
check that the mesh in the meshfilter matches the mesh collider mesh
- otherwise the mesh collider is pointing to an external mesh (e.g. from an fbx) - move to before for loop to ensure the meshfilter hasn't yet been modified
1 parent 1982e3c commit 40b4454

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

Assets/FbxExporters/Editor/ConvertToModel.cs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,21 @@ public static Dictionary<string,GameObject> MapNameToSourceRecursive(GameObject
374374
/// </summary>
375375
public static void CopyComponents(GameObject to, GameObject from){
376376
var originalComponents = new List<Component>(to.GetComponents<Component> ());
377+
378+
// Point the mesh included in the mesh collider to the mesh in the FBX file, which is the same as the one in mesh filter
379+
var toMeshCollider = to.GetComponent<MeshCollider>();
380+
var toMeshFilter = to.GetComponent<MeshFilter>();
381+
// if the mesh collider isn't pointing to the same mesh as in the current mesh filter then don't
382+
// do anything as it's probably pointing to a mesh in a different fbx
383+
if (toMeshCollider && toMeshFilter && toMeshCollider.sharedMesh == toMeshFilter.sharedMesh)
384+
{
385+
var fromFilter = from.GetComponent<MeshFilter>();
386+
if (fromFilter)
387+
{
388+
toMeshCollider.sharedMesh = fromFilter.sharedMesh;
389+
}
390+
}
391+
377392
// copy over meshes, materials, and nothing else
378393
foreach (var component in from.GetComponents<Component>()) {
379394
// ignore missing components
@@ -439,13 +454,6 @@ public static void CopyComponents(GameObject to, GameObject from){
439454
toRenderer.sharedMaterials = fromRenderer.sharedMaterials;
440455
}
441456
}
442-
// Point the mesh included in the mesh collider to the mesh in the FBX file, which is the same as the one in mesh filter
443-
if (to.GetComponent<MeshCollider> () != null && from.GetComponent<MeshFilter> () != null)
444-
{
445-
var toMeshCollider = to.GetComponent<MeshCollider> ();
446-
var fromFilter = from.GetComponent<MeshFilter> ();
447-
toMeshCollider.sharedMesh = fromFilter.sharedMesh;
448-
}
449457
}
450458
}
451459
}

0 commit comments

Comments
 (0)