My ViewController`s

I proceed by pressing any button on GameViewController, there I determine the level by the button title and load it:

let sceneView = GameScene(fileNamed: "Level " + String(buttonTitle)) let skView = SKView(frame: self.view.frame) self.view.addSubview(skView) skView.showsFPS = true skView.showsNodeCount = true skView.ignoresSiblingOrder = true sceneView!.scaleMode = .aspectFill skView.presentScene(sceneView) 

And then I can calmly go to the main menu using Segue:

 if node.name == "menu"{ self.viewController.performSegue(withIdentifier: "GoToMainMenu", sender: self) self.removeAllActions() self.removeAllChildren() } 

But if you go to any stage (any level) and update this level using the retry button:

 if node.name == "retry" { let currentScene = GameScene(fileNamed: "Level "+String(thisScene)) let transition = SKTransition.doorsCloseHorizontal(withDuration: 0.5) currentScene!.scaleMode = SKSceneScaleMode.aspectFill self.scene!.view?.presentScene(currentScene!, transition: transition) } 

Thats

 if node.name == "menu"{ self.viewController.performSegue(withIdentifier: "GoToMainMenu", sender: self) self.removeAllActions() self.removeAllChildren() } 

Stops working

I do not understand what's the matter.

    1 answer 1

    When updating / going backward / going forward, you need to initialize the ViewController:

     if node.name == "retry"{ print("retry") let currentScene = GameScene(fileNamed: "Level "+String(thisScene)) let transition = SKTransition.doorsCloseHorizontal(withDuration: 0.5) currentScene!.scaleMode = SKSceneScaleMode.aspectFill currentScene?.viewController = self.viewController self.scene!.view?.presentScene(currentScene!, transition: transition) } 

    Etc

    Go to menu:

     if node.name == "menu"{ self.viewController.performSegue(withIdentifier: "GoToMainMenu", sender: self) self.scene!.removeFromParent() self.scene!.view?.removeFromSuperview() self.removeFromParent() self.removeAllActions() self.removeAllChildren() }