meshFilter.mesh.name operates differently in standalone

Running the player in the editor, meshFilter.mesh.name is reporting the actual name of mesh, as expected.

However, when running a PC standalone it operates differently. Instead, it prints the name of the gameobject, not the mesh.

Debug.Log(gameObject.GetComponent<MeshFilter>().mesh.name);

or

Debug.Log(gameObject.GetComponent<MeshFilter>().sharedMesh.name);

Editor log when playing in editor:
mesh=cube Instance

Game log file when running the standalone:
mesh=zzzzzzzcube

Note, zzzzzzzcube is the name of the gameobject, not the mesh. The name of the mesh in the mesh filter is “cube”.
This made it hard to tell if static batching was working in build.
So I ran the FrameDebugger on the player and verified that the zzzzzcube’s mesh was being static batched.


.
The conclusion is right now I can’t rely on printing out the meshFilter.mesh.name or meshFilter.mesh.sharedMesh to see if the items are part of a combined mesh or not

Unity 2017.1.1f1

Same problem in Unity 2021.1

However it works ok for me with sharedMesh.name

Anyway it’s very confusing that mesh.name works differently on export indeed

From my testing it seems this is actually not simply a bug with the name, but with the instancing of meshes by calling meshFilter.mesh in Unity Standalone builds.

In my application I need to override the default bounds for certain instances of meshes, and unfortunately in Unity Standalone this happens as though I am calling sharedMesh rather than mesh. This means the bounds overrides are being applied to every instance of the mesh which leads to wrong behavior in build only.

1 Like

I’m having the same issue. I swap the mesh that is assigned to my player and am checking the mesh.name during collisions. When playing in the editor the correct mesh.name is returned. When debugging an Android session I can see that mesh.name is reporting “Player” instead.

I’m using 2021.2.11f1

1 Like

For me, the resolution was to swap to using sharedMesh.name instead of mesh.name:

var meshName = GetComponent<MeshFilter>().sharedMesh.name;

Update - I submitted a bug report for this issue and there is a tracker page for it now. Give it an up vote if you’d like to! Unity Issue Tracker - MeshFilter.mesh does not properly instance Meshes when used in Build