Search Unity

Load child mesh object

Discussion in 'Editor & General Support' started by VictorQianUnity, Aug 15, 2018.

  1. VictorQianUnity

    VictorQianUnity

    Joined:
    Nov 13, 2015
    Posts:
    30
    I need to load a specific part of the mesh in Editor.
    I tried to use var colMesh = AssetDatabase.LoadAssetAtPath(path,typeof(Mesh));
    But it will always load the first child, how can I load a specific one in Editor script?

    And I also tried AssetDatabase.LoadAllAssetRepresentationsAtPath(path);
    it does return all the child, but it won't let me to cast them to mesh

    View attachment 291872
     
  2. adriandevera

    adriandevera

    Joined:
    May 18, 2013
    Posts:
    8
    Is there any update to this? I would like to LoadAllChildren with a certain type hopefully something like:

    AssetDatabase.LoadAllAssetRepresentationsAtPath(path, typeof(mesh));
     
  3. eagle555

    eagle555

    Joined:
    Aug 28, 2011
    Posts:
    2,705
    That's because it returns GameObject types and Mesh types, to solve it I do:

    Code (CSharp):
    1. var meshes = UnityEditor.AssetDatabase.LoadAllAssetRepresentationsAtPath(path);
    2.  
    3. for (int i = 0; i < meshes.Length; i++)
    4. {
    5.     UnityEngine.Object m = meshes[i];
    6.  
    7.     if (m.GetType() != typeof(Mesh)) continue;
    8.  
    9.     if (m.name == meshName)
    10.     {
    11.         mf.sharedMesh = (Mesh)m;
    12.         break;
    13.     }
    14. }
    15.