I am trying to import a load of Meshes into a List via ‘Resouces.LoadAll’ however it keeps throughing back the following error. I dont understand. I suspect its something to do with the fact its a imported asset with a Mesh?
public class Smithing : MonoBehaviour {
public static List<Mesh> SwordSkins = new List<Mesh>();
public void Start()
{
SwordSkins.Add(Resources.LoadAll("FantasyCraft Assets/Items/Weapons/Sword Skins", typeof (Mesh)));
}
}
I’m pretty new to unity, but i’m pretty sure it order to use Resources.Load(), your files must be under a Folder named “Resources”
so, try moving “FantasyCraft Assest” to a new folder called “Resources”.
and to answer why you’re getting this error, it’s probably cause the method returns Null
Resource.LoadAll returns an Object[ ], an array of Objects. And you can’t Add this Object[ ]-array as a list item to your List, this is what the error message is telling you. You have to loop through the Object[ ]-array instead and add all of its elements individually “as Mesh” to your List
This is why I vaguely suggested using LoadAll instead, which returns an array of type T.
List.Add(T) only takes a single object as input, List.AddRange takes a collection such as a built-in array returned by LoadAll.