how to spawn a mesh at runtime ?

hi, like my title says, i’m wondering how to spawn a mesh, from my asset library at runtime ? i have searched on the forum and google without any clear response.

somebody can help me with this ?

thanks in advance for the help.

your mesh must Prefab in folder named “Resources”

var instance : GameObject = Instantiate(Resources.Load(“mymodel”, GameObject));

tried that but unity send me this error message

cs0266: cannot implicitly convert type 'UnityEngine.Object' to 'UnityEngine.GameObject'

don’t know how to make the conversion or cast it.

any help ?

Instantiate is a metho of Object, which is not the same as GameObject

Youc an typecast by appending “as gameObject” to the line or by using the generic version of Instantiate:

var instance : GameObject = Instantiate(Resources.Load("mymodel", GameObject)) as GameObject;
// or
var instance : GameObject = Instantiate.<GameObject>(Resources.Load("mymodel", GameObject));

(I would prefer the latter)

didn’t work, unity says Instantiate is not a generic definition.