- Home /
Strange error with unity.
NullReferenceException UnityEngine.Object.Instantiate (UnityEngine.Object original) (at C:/BuildAgent/work/cac08d8a5e25d4cb/Runtime/ExportGenerated/Editor/UnityEngineObject.cs:90)
I'm trying to simply populate an array with an object. Now that I got the script working it gives me this error.
Google came up with nothing on this.
Answer by mattyman174 · Mar 09, 2014 at 01:47 AM
If its the same line as your previous question. Make sure the directory your pointing to is correct. Also.
enemyPrefabs01[i] = Instantiate(GameObject.Find("Prefabs/Enemy Prefabs/prefab alien")) as GameObject;
Try instantiating it as a GameObject.
$$anonymous$$ade the change to that line as you suggested, but the error is still co$$anonymous$$g up.
I've triple checked the directory path, and it looks fine to me.
line now looks like this;
enemyPrefabs01[i] = Instantiate (GameObject.Find("Prefabs/Enemy Prefabs/prefab alien")) as GameObject;
The goal here, is to simply fill an array with X number of copies of this prefab so I can pool them and use them as needed during gameplay.
I got it working fine for me. Just ins$$anonymous$$d of GameObject.Find("Prefabs/Enemy Prefabs/prefab alien")
I created a directory called "Resources", inside the main directory Unity provides, and then Instantiate(Resources.Load("your diretory/your prefab"))
so your saying make a root directory called resources, and stick all my folders within that?
Yup, that's exactly what I'm saying. You dont need all of them, but at least the ones you will be instantiating things from