x


GUI Null Reference Exception?

Hi, all! I have three GUI Boxes in the OnGUI function. However, whenever I add the third into the code, I get the following error, repeated three times..

NullReferenceException: Object reference not set to an instance of an object Boo.Lang.Runtime.RuntimeServices.CheckNumericPromotion (IConvertible convertible)

What can I do to fix this? My code is as follows.

var skin : GUISkin;
var skin2 : GUISkin;
function OnGUI() {
    GUI.skin = skin;
    GUI.Box (Rect (10,10,Health.health * 3,30), "Health");
    GUI.skin = skin2;
    GUI.Box (Rect (10,40,Health.mana * 3,20), "Mana");
    GUI.skin = skin2;
    GUI.Box (Rect (10, 70,Experience.XP,20),"Experience");
}
more ▼

asked Aug 27 '10 at 05:52 PM

Borealis gravatar image

Borealis
1 1 1 2

Depending on what game object you attached this script too, you need to make sure you have your actual skinned textures dropped into your skin, and skin2 slots.

Aug 27 '10 at 08:09 PM lampshade
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

Are Experience and XP defined and have a value on startup? Try changing Experience.XP with 50 so you could verify if there's something wrong with that.

more ▼

answered Aug 27 '10 at 08:00 PM

Edy gravatar image

Edy
637 2 5 17

Ah, yeah. XP was set to 0, so the bar wouldn't have any height.

Aug 28 '10 at 06:05 PM Borealis

Great to see that you fixed the problem! You should then mark the answer as accepted :)

Aug 28 '10 at 10:40 PM Edy
(comments are locked)
10|3000 characters needed characters left

Check the following points:
- Health is not null
- Experience is not null
- skin and skin2 are not null

more ▼

answered Nov 22 '12 at 08:31 AM

DeveshPandey gravatar image

DeveshPandey
608 1 4 8

Vote up and accept it, if working!

Nov 28 '12 at 11:28 AM DeveshPandey
(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:

x3694
x399
x161
x62
x22

asked: Aug 27 '10 at 05:52 PM

Seen: 1446 times

Last Updated: Nov 28 '12 at 11:29 AM