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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Loading Mesh assets for MeshFilter assignment

Discussion in 'Editor & General Support' started by jc_crash, Feb 2, 2020.

  1. jc_crash

    jc_crash

    Joined:
    Jul 30, 2019
    Posts:
    21
    Hi all,

    I am having trouble using "AssetDatabase.LoadAssetAtPath" and even using "Resources.Load" to load a .mesh file in the editor hierarchy and assign it to a prefab's MeshFilter.

    I am doing this as an editor function, not application runtime. I am trying to use the following code:

    Code (CSharp):
    1. Mesh referenceMesh = (Mesh)AssetDatabase.LoadAssetAtPath(newMeshRefPath, typeof(Mesh)) as Mesh;
    The path is correct, I have triple checked it in debug and it is returning null. Can .mesh files be loaded like this? Does anyone have an alternative if not?

    Thanks!
     
  2. jc_crash

    jc_crash

    Joined:
    Jul 30, 2019
    Posts:
    21
    For anybody else that might be having this trouble...

    I was perusing the Unity documentation for other reasons a few days ago and noticed a mention of Unity's 'supported file extensions' and it got me to thinking. I believe .mesh is not actually a supported extension in Unity.

    If you are saving meshes that you want to assign later, rather than '.mesh', use '.asset' and it will solve the issues I describe above.