Search Unity

  1. All Pro and Enterprise subscribers: find helpful & inspiring creative, tech, and business know-how in the new Unity Success Hub. Sign in to stay up to date.
    Dismiss Notice
  2. Dismiss Notice

Swapping blender mesh on prefab instance - only showing partial mesh

Discussion in 'Scripting' started by petediddy, Apr 11, 2015.

  1. petediddy

    petediddy

    Joined:
    Mar 17, 2015
    Posts:
    19
    Hi everyone,

    I've got a main character that is a native Unity sphere. Then, the player can select a different character in the character selection screen and in the main game scene I am loading a different mesh based on the selection.

    I have created my replacement meshes in Blender, using multiple 3D shapes, and then joined into one mesh prior to exporting as a .fbx file and then importing into Unity. The meshes show correctly in the Unity preview (which makes me think they exported and imported correctly, but not totally sure). When I select the mesh object in my Assets folder in Unity, it shows that there is just one mesh attached (which seems correct, since I joined the meshes in Blender before exporting).

    However, when I get to the main game scene, only 2 of the original 10 mesh objects from Blender are showing (the head and nose of the character... but the eyes/hat/arms are all missing). The player is a prefab with my PlayerSkin script attached, where I have attached the Mesh selected earlier (this script is below).

    I've tried selecting the original objects and Mesh -> Normals -> Recalculate Outside but this didn't help.

    Any ideas? Probably a user error on my part. Using the latest Blender (2.74) and Unity 5. Any help greatly appreciated! I've just spent two days trying to figure this out and my brain is hurting.

    -pete

    Code (csharp):
    1.  
    2. usingUnityEngine;
    3. usingSystem.Collections;
    4.  
    5. publicclassPlayerSkin : MonoBehaviour {
    6.  
    7. publicMeshsnowman;
    8.  
    9. privateMeshmyMesh;
    10.  
    11. voidAwake () {
    12.  
    13. stringactiveSkin = PlayerPrefs.GetString ("activeSkin");
    14.  
    15. switch (activeSkin)
    16.  {
    17.  
    18. case"snowman":
    19.  {
    20. myMesh = snowman;
    21. break;
    22.  }
    23. default:
    24. break;
    25.  }
    26. GetComponent<MeshFilter> ().mesh = myMesh;
    27.  }
    28. }
    29.  
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    15,584
    One idea: does the new combined mesh refer to more than one material? The default sphere only has one material, so I'm not sure what Unity does if you replace the mesh filter's mesh with more materials than are slotted into the Renderer's .materials[] array at that moment.

    Another idea is to try it with a few trivial objects, joining some small number of objects (like three triangles) and seeing if they all are visible. If not, then write some code to dig into the mesh and export the verts/lines and see which is missing or if there is some numbering offset error in the triangle lists. I've seen certain 3d programs export damaged polys occasionally.
     
  3. petediddy

    petediddy

    Joined:
    Mar 17, 2015
    Posts:
    19
    So if I can see the full mesh with all of the objects and materials in the Unity preview, does that mean that it exported from Blender properly? I'm trying to cross some things off the list to narrow down the issue. Just because the full mesh and the materials are visible in the Unity preview window does that mean it exported fine?

    @Kurt Dekker - thanks for the ideas. Yes, I have multiple materials in the new combined mesh, and just one material in the original. I will try combining multiple simple objects into one in Blender with just one material and see if the entire combined mesh works. Also I'll have to do some digging to figure out your suggestion on digging into the mesh to export the vertices and lines to see if something is missing. Pretty much a noob on the coding thing.

    Thanks for the help!
    -pete
     
unityunity