This is the error I’m getting:
NullReferenceException
GameUtils..cctor ()
Rethrow as TypeInitializationException: An exception was thrown by the type initializer for GameUtils
GameUtils is a static class containing game state information and such. In my main menu scene, the StartGame button sets the CurrentGameState property in GameUtils before loading the level, but this error comes up, so the level doesn’t load. However, if I start in the level and quit to the menu, I don’t get this error and the level loads fine.
The MainMenu script uses several public fields from GameUtils, so I don’t see how GameUtils can be null.
Edit: Code included below
// this is in MainMenu OnGUI()
if (GUI.Button(new Rect(GameUtils.BUTTON_WIDTH / 2,
Screen.height - (4 * GameUtils.BUTTON_HEIGHT),
GameUtils.BUTTON_WIDTH, GameUtils.BUTTON_HEIGHT), "Match Play"))
{
GameUtils.CurrentPlayMode = PlayMode.Match;
Application.LoadLevel("Playfield");
}
// this is the property being accessed in GameUtils
public static PlayMode CurrentPlayMode { get; set; }
where PlayMode is an enum. I’m using an auto-implemented property; I’ve tried using a private field and a regular property that gets/sets it, but it made no difference.