Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

meshFilter.mesh.name operates differently in standalone

Discussion in 'Editor & General Support' started by ArachnidAnimal, Apr 21, 2018.

  1. ArachnidAnimal

    ArachnidAnimal

    Joined:
    Mar 3, 2015
    Posts:
    1,727
    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.

    Code (csharp):
    1.  
    2. Debug.Log(gameObject.GetComponent<MeshFilter>().mesh.name);
    3.  
    or
    Code (csharp):
    1.  
    2. Debug.Log(gameObject.GetComponent<MeshFilter>().sharedMesh.name);
    3.  
    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.

    sb.png
    .
    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
     
    Last edited: Apr 21, 2018
  2. Lemovision

    Lemovision

    Joined:
    Apr 6, 2020
    Posts:
    33
    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
     
  3. thebarryman

    thebarryman

    Joined:
    Nov 22, 2012
    Posts:
    122
    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.
     
    Last edited: Feb 9, 2022
    leftClaw likes this.
  4. lambch0p

    lambch0p

    Joined:
    Oct 22, 2014
    Posts:
    62
    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
     
    thebarryman likes this.
  5. lambch0p

    lambch0p

    Joined:
    Oct 22, 2014
    Posts:
    62
    For me, the resolution was to swap to using sharedMesh.name instead of mesh.name:
    Code (CSharp):
    1. var meshName = GetComponent<MeshFilter>().sharedMesh.name;
     
  6. thebarryman

    thebarryman

    Joined:
    Nov 22, 2012
    Posts:
    122