Have you tried to load the resource directly as gameobject? Or save the mesh as prefab and test it again. Unity - Scripting API: Resources.Load maybe that links helps, too
If you want to use Resources.Load, the asset needs to be in a folder called “Resources”, and you call Load using only the path from within that Resources folder, for example “Models/cubemesh”.
@SlyRipper
The mesh is already saved as an prefab. As I try to import the mesh as an gameobject I get this error:
NullReferenceExeption: Object reference not set to an instance of an object.
Here is my code:
private Mesh mesh;
GameObject meshObject = (GameObject)Resources.Load("Models/cubemesh", typeof(GameObject));
mesh = meshObject.GetComponent<MeshFilter>().mesh; //The IDE says that the error is located right here
InstantiateObject(mesh);
public void InstantiateObject(Mesh mesh)
{
//Create NPC object
npcObject = new GameObject(name);
MeshFilter meshFilter = this.npcObject.AddComponent<MeshFilter>();
meshFilter.mesh = mesh;
}
Like makeshiftwings mentioned… Do you have an “Resources” folder? Is there a “Models” folder inside of it? outside the Resources folder the method is not usable.
I got it. Yes, I already had an resources folder because all the YT videos I watched and the document on the reference told me I had to use a resource folder.