title: Segue between SKScene and UIViewController
body: <p>I'm writing simple math game with swift 3 and I have a problem with segues. I have two <code>GameViewController's</code>, one<code>UIViewController</code> and one <code>NavigationViewController</code>.<a href="https://i.stack.imgur.com/DBXZS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DBXZS.png" alt="enter image description here"></a> </p>
  
  <p>I want to make two menus, one with game modes and one with difficulties, I want that the difficulties menu be interactive and have gravity so I decided to make it in SkScene. Everything works fine except segue between SkScene with dark screen and difficulties menu when user lost the game. I write a protocol which works when I'm going from main menu to second menu but when I'm going from SkScene with game it doesn't. I was trying to make a manual segue but protocol doesn't want to execute. <a href="https://i.stack.imgur.com/euCNx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/euCNx.png" alt="enter image description here"></a></p>
  
  <p>MyGVViewController code:</p>
  
  <pre><code>    import UIKit
      import SpriteKit
      import GameplayKit
  
      enum skad1 {
       case game,menu
       }
      var skad = skad1.gra
  
      class MyGVViewController: UIViewController, GameViewControllerDelegate {
  
  override func viewDidLoad() {
      super.viewDidLoad()
  
      if let view = self.view as! SKView? {
          // Load the SKScene from 'GameScene.sks'
          if let scene = SKScene(fileNamed: "Menugame") {
              let gameScene = scene as! MySKScene
              gameScene.gameViewControllerDelegate = self
              gameScene.scaleMode = .aspectFill
  
  
              gameScene.size = view.bounds.size
  
              // Present the scene
              view.presentScene(gameScene)
          }
  
          view.ignoresSiblingOrder = true
  
          view.showsFPS = true
          view.showsNodeCount = true
      }
  }
  
  override var shouldAutorotate: Bool {
      return true
  }
  
  override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
      if UIDevice.current.userInterfaceIdiom == .phone {
          return .allButUpsideDown
      } else {
          return .all
      }
  }
  
  override func didReceiveMemoryWarning() {
      super.didReceiveMemoryWarning()
      // Release any cached data, images, etc that aren't in use.
  }
  
  override var prefersStatusBarHidden: Bool {
      return true
  }
  
  func goback() {
      print("goback executed")
      let view = self.view as! SKView?
      view?.presentScene(nil)
      navigationController?.popViewController(animated: true)
  
  }
  func goback2() {
      print("goback2 executed")
      let view = self.view as! SKView?
      view?.presentScene(nil)
      self.performSegue(withIdentifier: "comeback", sender: nil)
  }
  
  }
  </code></pre>
  
  <p>My SkScene with difficulties menu code:</p>
  
  <pre><code> import GameKit
   import SpriteKit
   import CoreMotion
  
   protocol GameViewControllerDelegate: class {
      func goback()
      func goback2()
   }
  
  
  
  class MySKScene: SKScene {
  
  //Variables
  
  var motionManager: CMMotionManager!
  var ball = SKSpriteNode()
  var ball1 = SKSpriteNode()
  var ball2 = SKSpriteNode()
  var ball3 = SKSpriteNode()
  var ball4 = SKSpriteNode()
  weak var gameViewControllerDelegate: GameViewControllerDelegate?
  
  override func touchesEnded(_ touches: Set&lt;UITouch&gt;, with event: UIEvent?) {
  
      for touch in touches {
          let location = touch.location(in: self)
          if ball.contains(location){
              showgame(zakres: 200)
          }else if ball1.contains(location){
              showgame(zakres: 100)
          }else if ball2.contains(location) {
              showgame(zakres: 50)
          }else if ball3.contains(location) {
              showgame(zakres: 150)
          }else if ball4.contains(location) {
              if skad == .menu{
                  print("should execut goback")
                  self.gameViewControllerDelegate?.goback()
              }else{
                  print("should execut goback2")
                  self.gameViewControllerDelegate?.goback2()
              }
          }
      }
  }
  
  func showgame(zakres:Int) {
  
      if let view = self.view {
          range = zakres
          // Load the SKScene from 'GameScene.sks'
          if let scene = SKScene(fileNamed: "GameScene") {
              // Set the scale mode to scale to fit the window
              let gameScene = scene as! GameScene
              gameScene.scaleMode = .aspectFill
  
              // Present the scene
              gameScene.size = view.bounds.size
              view.presentScene(gameScene)
          }
  
          view.ignoresSiblingOrder = true
  
          view.showsFPS = true
          view.showsNodeCount = true
      }
  }
  
  
  
  override func didMove(to view: SKView) {
  
      ball = self.childNode(withName: "ball") as! SKSpriteNode
      ball1 = self.childNode(withName: "ball1") as! SKSpriteNode
      ball2 = self.childNode(withName: "ball2") as! SKSpriteNode
      ball3 = self.childNode(withName: "ball3") as! SKSpriteNode
      ball4 = self.childNode(withName: "ball4") as! SKSpriteNode
      motionManager = CMMotionManager()
      motionManager.startAccelerometerUpdates()
      let border = SKPhysicsBody(edgeLoopFrom: self.frame)
      border.friction = 0
      border.restitution = 0
      self.physicsBody = border
  }
  
  
  override func update(_ currentTime: TimeInterval) {
      if let accelerometerData = motionManager.accelerometerData {
          physicsWorld.gravity = CGVector(dx: accelerometerData.acceleration.x * 20, dy: accelerometerData.acceleration.y * 35)
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>PS.<br>
  I'm reading what I wrote and I have to correct it, in difficulties menu I have a button which execute protocol that hide SKScene and show main menu. It works only when I'm going from main menu but when segue is from game when user lost, protocol isn't executed </p>