ArgumentException: The prefab you want to instantiate is null.

I get the above error when implementing the following code. I have cut it down to what I think are the essential bits of code to make it easier to read. If you need more please let me know.

public GameObject WolfObject;//prefab has been dragged into this object
public GameObject SpeciesInstantiate(string SpeciesName,int IDNameNumber)

			var NewGameObject=GameObject.Instantiate(WolfObject,Position,Quaternion.identity);;return (GameObject)NewGameObject;}


That is called as follows:

public class EnvironmentalEngine : MonoBehaviour 
GameObject ComObj;
void Start () 
		ComObj=GameSpecies.SpeciesInstantiate(SpeciesTag[j],ObjectLibrary.WorldSpeciesCount[j]);	}

Thanks in advance for any help :slight_smile:

Thanks for all the responses. After trawling the net I have found what makes it work:

Take the prefab that you want to Instantiate and put it in a folder (you will have to create it in the project folder) called “Resources”. Place the prefabs that you wish to Instantiate in there. In this case the prefab is called “Wolf”.

Then change this line:

var NewGameObject=GameObject.Instantiate(WolfObject,Position,Quaternion.identity);


var NewGameObject=GameObject.Instantiate(Resource.Load("Wolf"),Position,Quaternion.identity);

And now it works! :slight_smile:

if you wish to organise your prefabs in a subfolder of Resources you must first make a folder named “Prefabs” within Resources. Move your subfolder there.

In Javascript you can then load thusly:
var NewGameObject : GameObject = Resources.Load(“Prefabs/Your SubFolder/Your Prefab”),,Quaternion.identity);

You must also remove the “.prefab” extension from your FileName string.