I’m not sure if I’ve lost my mind and I’m doing something stupid that I’m just not seeing but here is the problem. I started having trouble with this bug in my game and decided to start a new project with just the barebones setup needed to reproduce it.
All I’m doing is very simple.
- Imported mesh.
- Created prefab “testPrefab” of mesh.
- Created “Game” empty gameobject in Hierarchy.
- Created “Game.js” script and attached it to “Game” object in Hierarchy.
var test : Transform;
function Start()
{
print("test = " + test);
Instantiate(test, Vector3(0,0,0), Quaternion.Identity);
}
I’ve assigned the “test” prefab to the target variable exposed in “Game”.
In the console the print function prints this
test = testPrefab (UnityEngine.Transform)
UnityEngine.MonoBehaviour:print(Object)
Game:Start() (at Assets/Game.js:5)
Everything seems fine there, I think, it sees it right ?!?!? But then I get
NullReferenceException: Object reference not set to an instance of an object
Game.Start () (at Assets/Game.js:6)
I assume I’m making some silly blunder but, I’ve been doing things similar to this for months now without trouble, I just don’t understand.
I’ve tried restarting Unity, rebooting computer, completely new project, importing a different mesh… I don’t know, any ideas?