ArgumentException: The prefab you want to instantiate is null.

I am rather new to Unity and C#, and need help. I have looked around on the forums for people with similar problems but have yet to find anything that helps.

There are two game objects that need to be instantiated a wolf-object and a rabbit-object. I have scripted them in two different ways which seem the same to me. Why is does instantiating the wolf-object throw the above error and how can I correct this? In both cases the prefab has been assigned to their relevant scripts.

using UnityEngine;
using System;
using System.Collections;
using System.IO;
using System.Linq;

public class SpeciesCreation : MonoBehaviour { 	

	public GameObject RabbitObj;
	
	int RabbitInit=30;
	
	WolfProps p=new WolfProps();
	
	void Start () 
	{	
		p.WolfCreate();
		
		for(int i=1;i<=RabbitInit;i++)
		{
    		var RabbitObject = GameObject.Instantiate(RabbitObj, new Vector3((float)(UnityEngine.Random.value-0.5)*90f+50f,100.25f,(float)(UnityEngine.Random.value-0.5)*90f+50f),Quaternion.identity);
	}			
	}
	void Update ()
	{
		EquilibriumMathEngine.EquilibriumCalc();
	}
}


using UnityEngine;
using System.Collections;

public class WolfProps : MonoBehaviour 
{	
	public GameObject WolfObj;

	
	public int WolfCreate()
	{
		{	
			var WolfObject = GameObject.Instantiate(WolfObj, new Vector3((float)(UnityEngine.Random.value-0.5)*90f+50f,101.25f,(float)(UnityEngine.Random.value-0.5)*90f+50f),Quaternion.identity);
			return 1;
		}
	}	
}

Thank you in advance for any help :slight_smile:

Thanks for the reply.

I have dragged the prefab representing the Wolf-object into script and tried that. Then I dragged the script over onto the wolf prefab. Neither worked.

If I made the mistake that I think you are speaking of would it not give the following error:
“UnassignedReferenceException: The variable has not been assigned.”