title: Architecture of a SceneKit game, multiple view controllers for menu screens?
body: <p>I'm working on a SceneKit game using Swift, and I'm thinking about the best way to organize the various screens/ states surrounding the actual main game scene. I have a simple prototype which consists of three states:</p>
  
  <ul>
  <li>Splash Screen (choose game type) -> </li>
  <li>Game -> </li>
  <li>Game over screen (choose to play again or return to splash)</li>
  </ul>
  
  <p>In the prototype I opted to go for UIKit to do the UI elements, rather than a SpriteKit overlay. Although it's just buttons at the moment, which would be easy enough to do in SpriteKit, I might in future want to add sliders (eg an options screen to set control sensitivity etc), text entry etc, and then you end up recreating great chunks of uikit.</p>
  
  <p>So at present, each of the 3 scenes described above has its own <code>UIViewController</code>. The Splash and Game ViewControllers have their own <code>SCNView</code>s and <code>SCNScene</code>s, and the GameOver is a modal that displays over the main Game scene. </p>
  
  <p>This structure isn't really ideal, as it means that the main game SCNScene gets reloaded whenever the <code>viewDidLoad</code> of the <code>GameViewController</code> fires. The main <code>SCNScene</code> is quite detailed so takes a few seconds to load, and with repeated cycles this seems to create memory issues. After 2 cycles of Splash -> Game -> GameOver I get a memory warning, and after the third cycle Xcode loses the connection to the iPhone (which seems, in my experience, to be caused by memory issues). </p>
  
  <p>I would like to have a main <code>GameViewController</code> that loads the most frequently reused assets once, but still be able to segue between the various menu screens.</p>
  
  <p>So what are the options here? </p>
  
  <p>I thought perhaps I could have a main <code>GameViewController</code> which controls the loading and unloading of SceneKit assets and has the sole <code>SCNView</code>. Its <code>viewDidLoad</code> method would only be fired once, when the app first starts. Then, each of the other views would have a very minimal <code>UIViewController</code>, which would be presented as modals over the main GameViewController, with "OverCurrentContext" selected.</p>
  
  <p>I wanted to ask whether this pattern sounds feasible, and how others organise their SceneKit games. I'm still quite new to native iOS development, so it could be that I'm missing some basic game design pattern.</p>