Instantiate an element of an array of objects

What is wrong with this? It gives me a null reference exeption error.

   #pragma strict
        
    var models : GameObject[];
    
    function Start(){
        models = Resources.LoadAll("Objects/AMM_0002")as GameObject[];
        
        var instance : GameObject = Instantiate(models[0],Vector3.zero,Quaternion.identity) as GameObject;
    }

The simple Resources.LoadAll() does not return an GameObject. It does return an Object.

Even if all elements of the array happen to be of type GameObject, that doesn’t mean you can just cast it to a GameObject. By using the “as” operator, you are saying “If this is an GameObject, give it to me. If not, give me null” which is what you got.

Just use the LoadAll.<> function instead:

models = Resources.LoadAll.<GameObject>("Objects/AMM_0002");