Hello,
I am trying to instantiate a prefab from resources folder using the name from a text file located in my resources folder. Prefab is also located in my resources folder. However, I get an error saying “the object I want to instantiate is null”.
When I directly give the name of prefab it works. I cannot seem to understand the issue.
My code is :
public void Loadd()
{
TextAsset txtasset = (TextAsset)Resources.Load (txtfile);
txtcontents = txtasset.text;
string[] linesinfile = txtasset.text.Split ('
');
for(int i= 0; i<1; i++){
for (int x = 0; x < buttonholder.Length; x++) {
//GameObject Instance = Instantiate (Resources.Load ("F260001", typeof(GameObject))) as GameObject; // works
string name = linesinfile [x];
Debug.Log (name);
GameObject Instance = Instantiate (Resources.Load (name, typeof(GameObject))) as GameObject;
}
}
}