Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6807053
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:47:07+00:00 2026-05-26T19:47:07+00:00

I have a little engine (defined as public class ScreenManager : DrawableGameComponent ) to

  • 0

I have a little engine (defined as public class ScreenManager : DrawableGameComponent) to manage input and screens (with transitions etc.), who works with a public abstract class GameScreen. For menu screens I have an abstract class MenuScreen : GameScreen.
I’m trying to get from class OptionsMenuScreen : MenuScreen a value stored in the main class of the game (the one called by Program.cs), but I always get NullReferenceException. I need that value because while starting application I need to get some option and these options can be changed from OptionsMenuScreen, but I want that changes from that screen automatically reflects on the rest of application, so a screen can base it’s computation on that value, without force the user to reload entire application to get values in main class updated.
I do this with

public ScreenManager ScreenManager
{
    get { return screenManager; }
    internal set { screenManager = value; }
}

ScreenManager screenManager;

in GameScreen.cs and

/// <summary>
/// Adds a new screen to the screen manager.
/// </summary>
public void AddScreen(GameScreen screen, PlayerIndex? controllingPlayer)
{
    screen.ControllingPlayer = controllingPlayer;
    screen.ScreenManager = this;
    screen.IsExiting = false;

    // If we have a graphics device, tell the screen to load content.
    if (isInitialized)
    {
        screen.LoadContent();
    }

    screens.Add(screen);

    // update the TouchPanel to respond to gestures this screen is interested in
    TouchPanel.EnabledGestures = screen.EnabledGestures;
}

as method to add a Screen to ScreenManager’ list of screens.
But when I try to do something like

separateAxis = (ScreenManager.GameInstance as Main).SeparateAxis;

I get always NullReferenceException. Despite it works from other Screens (deriving directly from GameScreen, not MenuScreen).

Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T19:47:08+00:00Added an answer on May 26, 2026 at 7:47 pm

    There are 2 posibilies from your code, either ScreenManager is null, or (ScreenManager.GameInstance as Main) is.


    For the first case:

    I think you’re calling your problem line from within the option screen’s constructor, or at least before the screenmanager’s AddScreen method is called.

    Move it to the screen’s LoadContent method.

    For the second case:

    Check that GameInstance is an instance of Main.


    It’s worth noting that this is the GameStateManagement sample you’re basing your code on.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So, I'm writing a game engine. I have a little example (see http://qrcode.kaywa.com/img.php?s=8&d=http://rokonandroid.com/rd.apk ),
I have a shopping site that works a little bit differently than the rest:
I have built a variety of little scripts using Ruby's very simple Queue class,
I'm hacking a little template engine. I've a class (pompously named the template compiler
I have a little console application that has an embedded v8 engine, and I
I have a little problem with my Solr search engine. It does not return
We have a print engine which basically picks pre defined tasks to run against
I have been working on a game engine for the last little while and
I have little knowledge of Flash but for a little Flash game I have
i have little problem with boost::asio library. My app receive and process data asynchronously,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.