Solution to MissingReferenceException w/ prefab?

alright I’ve rewritten the entire question because it was rather unclear before;

What I am trying to do is instantiate a prefab that exists as a variable in another script.

class myClass {             //Just a class to represent the     
    var item : GameObject;  //class I have in my script
}

var a_Class : myClass = myClass();

function create () { //Instantiate the gameobject from "item"
    Instantiate(a_Class.item,//position,//rotation); 
}

The only issue with this script is that the item variable comes from a gameObject that has been destroyed…so when i try to instantiate it over again, i receive a “GameObject you are trying to access has been destroyed” error because the prefab from which i got the item variable has been removed from the game world.

what i need is a way to retain this prefab because the prefab that i am adding and removing from an array i have in the script is the same and has itself assigned to “item”.

Your question is not clear. I agree on aldonaletto’s comment.

I think you are getting problem to instantiate a prefab at runtime. Seems prefab reference problem.

You can create a ‘Resources’ folder in Assets folder of your project and move your prefab(s) to ‘Resources’ folder. Now, you can instantiate your prefab(s) run-time like this:

Instantiate (Resources.Load ("myPrefab", typeof(GameObject)));

Make sure ‘myPrefab.prefab’ file exists in ‘Assets/Resources’ folder, or else you will get a NullReference Exception.