[fixed] Prefab is null - Strange Instantiate problem

Hi,

I’m having a really odd problem. I’m trying to do something VERY simple. I’ve talked to a more experienced Unity developer (hi!), and sent my project over to him to take a look it. It works on his machine.

var objectToClone:GameObject;
function Start()
{
	Debug.Log("start");
	Instantiate(objectToClone, transform.position, transform.rotation);
}

This script is attached to an empty GameObject called ‘MainGameObject’.

I have a very simple prefab - called MyPrefabCube. It’s a cube primitive that I’ve dragged and dropped onto the prefab called MyPrefabCube.

I have selected the script, and in the Inspector dropdown I’ve selected ‘MyPrefabCube’.

When I press play, I get the following in the console:

start
UnityEngine.Debug:Log(Object)
MainScript:Start() (at Assets\MainScript.js:5)

NullReferenceException: The prefab you want to instantiate is null.
UnityEngine.Object.Instantiate (UnityEngine.Object original, Vector3 position, Quaternion rotation) 
MainScript.Start ()   (at Assets\MainScript.js:6)

When I sent this to my friend, ‘none’ was selected in the inspector for ObjectToClone, so he selected MyPrefabCube. It then worked as expected.

So, either I’m doing something VERY stupid (highly likely), in which case tell me what I’m doing wrong and laugh a lot, or my copy of Unity is being screwy (unlikely).

In addition to this, frequently the spinning circle thing in the bottom right corner of the main window spins for a very long time when I change this script.

I am said friend, and I can confirm that yezzer is no fool, so there’s definitely something weird going on.

My suggestion was to save, close, restart PC, make a cup of tea, come back: hey presto it’ll probably work - just like Flash does/doesn’t sometimes :slight_smile:

sadly a restart hasn’t fixed it :frowning:

Ok, I’ve found out what I was doing wrong. I’m going to hide in a little corner somewhere and regret wasting hours on something so easy.

Can you explain what the solution was? I seem to be having the same problem.

It sounds like the same prefab mistake I made.
i.e. MyPrefabCube was hooked directly to the script as a default, and not the script instance attached to the object
I just posted full details here.