x


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.

more ▼

asked Jul 02 '12 at 10:54 PM

Wuzseen gravatar image

Wuzseen
133 3 10 13

More relevant it's code where the variable generateSpheres it's used. If the debugger say the variable it's not assigned mean exactly that; in a way or other the generateSpheres it's loosing the reference to the multiplierPickup during of gameplay.

Jul 03 '12 at 08:20 AM nastasache
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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

more ▼

answered Jul 03 '12 at 03:46 PM

Wuzseen gravatar image

Wuzseen
133 3 10 13

(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered Jul 03 '12 at 08:29 AM

roamcel gravatar image

roamcel
1.2k 37 40 44

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x718
x197
x128
x5

asked: Jul 02 '12 at 10:54 PM

Seen: 321 times

Last Updated: Jul 03 '12 at 03:46 PM