Search Unity

Resources.load failed

Discussion in 'Scripting' started by pierre_l, Nov 23, 2017.

  1. pierre_l

    pierre_l

    Joined:
    Aug 24, 2017
    Posts:
    28
    I'm trying to create a new gameobject at runtime and assign it a mesh.
    In my subfolder Assets/toto there is a 3ds file named mymesh.3DS including a mesh named struct (I can chek the mesh named struct in the Mesh selection Editor of Unity).

    My instructions are :
    Code (CSharp):
    1. Mesh TMesh = (Mesh)Resources.Load("Assets/toto/mymesh.3DS", typeof(Mesh));
    2.             var Objet = new GameObject();
    3.             Objet .AddComponent<MeshFilter>();
    4.             Objet .AddComponent<MeshRenderer>();
    5.             Objet .GetComponent<MeshFilter>().mesh = TMesh;
    But the mesh does'nt load when I run the script. I can check it in the EditBox of the mesh Filter editor indicating None (Mesh)
     
    Last edited: Nov 23, 2017
  2. Akzafield

    Akzafield

    Joined:
    Aug 20, 2017
    Posts:
    17
    Hello.
    You probably have the same problem :
    https://forum.unity.com/threads/resource-load-question.505348/#post-3294123

    https://docs.unity3d.com/462/Documentation/ScriptReference/Resources.html
    "All assets that are in a folder named "Resources" anywhere in the Assets folder can be accessed via the Resources.Load functions. Multiple "Resources" folders may exist and when loading objects each will be examined."
    https://docs.unity3d.com/ScriptReference/Resources.Load.html
    "The path is relative to any Resources folder inside the Assets folder of your project"

    (Resources.Load need a Resource folder to be able to Load a file)
     
  3. pierre_l

    pierre_l

    Joined:
    Aug 24, 2017
    Posts:
    28
    oh well I'm an idiot too. Thks a lot!
    I cumulated 2 errors, the folder and the extension.
     
    Last edited: Nov 23, 2017