State Machines for game states

Hello everyone,

I am relatively new to unity and was digging around on various tutorials for a bit and noticed that most people in their tutorials seem to use scenes for specific states instead of various game states as us you would in C++ and DirectX. For example from what I can tell they have a Main menu scene, a game scene, and a end game scene instead of your standard Game State system where you have a CMainMenuState and a CPlayingState that derived from a base state. So my question is what are the reasons for this and is their more overhead from having multiple scenes. Also if anyone can point me in a direction that uses a statemachine to change game states in unity In I would appreciate it. I appreciate any feedback thanks everyone.

The overhead from multiple scenes is negligible. And it has the following advantages:

  • Initial scene loads quicker - this can be especially important on mobile platforms
  • Assets that are not needed by a scene are unloaded when you switch
  • It is a logical way to divide and test the game

It has some disadvantages:

  • Some data needs to be carried over between scenes. (It can either be stored in PlayerPrefs or there can be a manager object that stays loaded across all scenes. See: http://answers.unity3d.com/questions/841/scene-connecting)
  • If you develop a menu scene, for example an options menu, you may have extra work later if you want to have the user be able to adjust the options while the game is playing.

See also discussion here: http://answers.unity3d.com/questions/24956/what-is-the-best-way-to-structure-a-game-with-menu-and-levels-plus-a-level-select