- Home /
NullReferenceException: Object reference not set to an instance of an object
Hi all, I keep getting lots of these errors: NullReferenceException: Object reference not set to an instance of an object PauseMenu.OnGUI () (at Assets/Scripts/GUI/PauseMenu.js:83) Can someone please help me edit this code so the error is gone. Original seller of code no longer available.
function OnGUI () {
if (gameStatus.mainMenu.guiSkin != null)
GUI.skin = gameStatus.mainMenu.guiSkin;
GUI.color = gameStatus.mainMenu.guiColor;
if (isMainMenu) {
GUI.Label (Rect(0, Screen.height * 0.05, Screen.width, Screen.height * 0.1), gameStatus.mainMenu.gameTitle, gameStatus.mainMenu.titlesGuiStyle);
} else if (IsGamePaused()) {
if (pauseEffect == null && gameStatus.mainMenu.alternateBackground != null) {
var backgroundStyle : GUIStyle = new GUIStyle();
backgroundStyle.normal.background = gameStatus.mainMenu.alternateBackground;
GUI.Label (Rect(0, 0, Screen.width, Screen.height), "", backgroundStyle);
}
Also for: NullReferenceException: Object reference not set to an instance of an object PauseMenu.Start () (at Assets/Scripts/GUI/PauseMenu.js:41)
function Start () {
Time.timeScale = 1.0;
if (Screen.fullScreen)
GameStatus.fullscreenMode = true;
GameStatus.savedRes.width = Screen.width;
GameStatus.savedRes.height = Screen.height;
gameStatus = FindObjectOfType(GameStatus);
levelStateMachine = FindObjectOfType(LevelStatus);
if (levelStateMachine != null)
player = LevelStatus.player;
scrollPosition = Vector2(gameStatus.mainMenu.menuWidth, gameStatus.mainMenu.menuHeight * 0.5);
if (isMainMenu)
PauseGame();
else
Screen.lockCursor = true;
ShowLevelName();
}
Could you tell us at what lines the errors correspond to your copied code ? What is line 83 in the OnGui method and what is line 41 in Start method ?
Sorry about this, yes sure.
Line 83 = in the above code Line 2 Line 41 = in the above code Line 12
gameStatus is not with a capital "G", contrary to GameStatus used in the Start method.
This is the same for the other error, try that, there may be other errors, just tell me.
Not sure what you mean: (private var gameStatus : GameStatus;) This is declared at start of script Can you type the line how you think it should look like?
It's confusing because you use a variable named gameStatus, and you also use GameStatus in the Start method. I'm not sure to really understand why you use both.
Your answer
![](https://koobas.hobune.stream/wayback/20220613115454im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
NullReference Exception when checking for Null 1 Answer
Detecting gameObject from 3D rayCast 1 Answer
Codes unavailable in C# 0 Answers
GameObject.Find/WithTag returns null 1 Answer
I can't run simple movement script from "Space Shooter". 1 Answer