Search Unity

Unity Game State Management - How?

Discussion in 'Editor & General Support' started by tharealjohn, Dec 20, 2012.

  1. tharealjohn

    tharealjohn

    Joined:
    Jul 19, 2012
    Posts:
    5
    Hello Unity Community,

    I have spent my last 2 weeks worth of free time working on my unity project. Specifically, trying to implement a state management system for my game. I am trying to make a way for easy switching of Title Screen, Main Menu, Game Play, Level Select screen, etc. I have read just about every link on google for topics like "Unity3d game management", "Unity3d game states" etc. I have not found a good way that I am satisfied with yet. I spent some time researching before posting here, but now after finding nothing concreted, I figured I would ask the community.

    The only real solid information I could find that was almost complete were similar to these two methods:

    Global GameObject that persists through scene transitions and implements a singleton pattern. Something like GameManager and has a function for ChangeState(GameState newState).

    This sounds great, only it gets large fast. I was not able to find a great example of how to handle drawing each screen, actually handling different scenes, etc. This example doesn't necessarily use separate scenes for each state e.g. MainMenuScene, GamePlayScene, etc.

    The next method I found is like above, but using separate scenes where an object in the scene has scrips attached to it for drawing the GUI. This makes the most sense to me and is probably the easier to implement, but its got some other limitations im not satisfied with.

    How are you handling Game state management and different screens and menus, and interactions between them? I am having a hard time with this, mainly because of the component/gameObject pattern in Unity. It is a bit of a change from I used to coming from XNA.

    Any suggestions, examples, advice would be amazing. Please be as specific as you can. The basics are great, but think bigger.

    Thanks!
     
  2. SteveJ

    SteveJ

    Joined:
    Mar 26, 2010
    Posts:
    3,085
    What do you mean by "This sounds great, only it gets large fast"?
     
  3. tharealjohn

    tharealjohn

    Joined:
    Jul 19, 2012
    Posts:
    5
    When I tried to implement it, I didnt understand how to organize it so that I wouldnt have a ton of code for GUI related items in the managers OnGUI(). I also ended up having a lot of "management" type objects in my scene. When I broke it up into "each state is a scene" design, things were more manageable, but its hard to implement floating menus and share data between scenes.
     
  4. Swearsoft

    Swearsoft

    Joined:
    Mar 19, 2009
    Posts:
    1,632
    I use one object that is persistent and I have also split up my scenes based on how the menu screens work together.
     
  5. makeshiftwings

    makeshiftwings

    Joined:
    May 28, 2011
    Posts:
    3,350
    You could also save all of your GUI screens and components as one big prefab, and then put that prefab in each scene. Just make sure that if you make any changes to it in one scene, you click Apply to affect the prefab and then refresh those changes in your other scenes.