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.