Exceptions When Changing Scenes

Hi all,

I’ve got a simple main menu in my game and when I start my game from this menu, I get NullReference and UnassignedReference exceptions for the first person controller motor and a prefab I’ve made respectively. Specifically, the Transform variable I have in a script (generateSpheres) that refers to a prefab (multiplierPickup) I’ve made, has not been assigned according to the error.

When I simply play the scene I’m transitioning into I have no issues whatsoever. Indeed, all of these things are assigned in the correct scene.

Here’s the code that loads my level. My problem is though, I’m not really sure what is relevant to the problem.

function OnMouseUp()
{
 if( !isQuit )
 Application.LoadLevel("main");
 else
 Application.Quit();
}

As I said, I’m not entirely sure what’s going on here. I don’t know what code is relevant, etc. Hopefully you guys can understand the issue though.

The debugger suggest that I need to define the variable in the inspector view for the script. This has been done, I just don’t know what’s still causing issues. It was working at first, but I added in a second type of prefab/pickup. While there are no issues with the scene I am loading when I just load that scene, when I load it from my mainMenu scene, I have these errors.

This might be a tricky problem:
if you assign a new gameobject to a TRANSFORM, there’ll be no compiling errors… but you’ll get runtime errors!

Make sure that you assign the instance to a GAMEOBJECT rather than a transform. This should fix your problem.

I legitimately have no clue as to how I fixed the problem. It just fixed itself and that’s all I really know.