Gamescene.swift and Gamescene.sks not working together Gamescene.swift and Gamescene.sks not working together xcode xcode

Gamescene.swift and Gamescene.sks not working together


i managed to fix the problem after countless hours of trying.

    if let view = self.view as! SKView? {        // Load the SKScene from 'GameScene.sks'        if let scene = GameScene(fileNamed: "GameScene") {            // Set the scale mode to scale to fit the window            scene.scaleMode = .resizeFill

this is the working code. the problem was that instead of specifying what scene i was suppose to lead i had written

if let scene = SKScene(fileNamed: "GameScene")

the simple fix was changing the "SKScene" to my SKScene name.

if let scene = GameScene(Filenamed: "GameScene") 

Hope this helps the countless other out there that are having trouble with this problem!


I've had similar problems to this on SOME of my projects but not all. Even on projects that were working and I duplicated the code and scene files for another project they would stop working. I discovered that if there are any spaces or special characters in the your project name the scene files and items in the sks files will not load unless you put in the "Module" name below the Custom Class type.

For me my project was named "Crag & Pig" before any of the sks file would register I had to enter "Crag_Pig" in the "Module" for all of the items in the sks file.

Interestingly, on any projects that didn't have spaces or special characters I didn't have to enter any thing for Module


Thanks. Even the default template in Xcode for SpriteKit Games has this very issue. That since the release of swift 4 + iOS 11. I always thought it was me somehow, but never took the time to find why. Until now out of curiosity. I changed the line you wrote/fixed and voila.

Just changed the capitals in the parameter fileNamed: of your line

if let scene = GameScene(fileNamed: "GameScene")