- Home /
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");
}
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.
Answer by Edy · Aug 27, 2010 at 08:00 PM
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.
Ah, yeah. XP was set to 0, so the bar wouldn't have any height.
Great to see that you fixed the problem! You should then mark the answer as accepted :)
Answer by DeveshPandey · Nov 22, 2012 at 08:31 AM
Check the following points:
- Health is not null
- Experience is not null
- skin and skin2 are not null
Your answer
Follow this Question
Related Questions
NullReferenceException in for-loop 0 Answers
GUI box problem? 0 Answers
Change colour of GUI box, keep round corners. 0 Answers
How To Get Current Mouse Position and have a GUI Box on right clicked 2 Answers
Simple GUI Question 1 Answer