Cannot decode object of class (GameScene) for key (root)

After some weeks of dealing with UIKit, I wanted to start with SpriteKit. I have used the 'Game' template in Xcode with SpriteKit and have not changed anything. Now, whenever I try running the app, it crashes when loading the GameScene on this line in GameViewController.swift:

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


Executing po $arg1 on objc_exception_throw prints this:

*** -[NSKeyedUnarchiver decodeObjectForKey:]: cannot decode object of class (GameScene) for key (root); the class may be defined in source code or a library that is not linked
(null)


I am using Xcode 8.0 beta and iOS 10, which may be the problem, but is there any other way to fix this? (Creating and running a new project in Xcode 7.3 with using the same settings works fine, but I want to get used to Swift 3 which is why I'm using Xcode 8 beta).


Also, opening GameScene.sks in either Xcode 7.3 or 8 crashes Xcode everytime, showing this error:

Assertion failed: (*shader), function xglCompileShader, file /Library/Caches/com.apple.xbs/Sources/Jet/Jet-2.17/Jet/xgl_utils.mm, line 24.

(I assume that this may be caused by the fact that I'm using a virtual machine.)


Thanks in advance

Simon J.

Replies

i have the same problem with xcode 8 on mac mini 2012

This is my exact problem, execpt I am running on Xcode 7.3.1, and my "Assertion failed:" says

Assertion failed: [... (same exact stuff)]/com.apple.xbs/Sources/Jet/Jet-2.6.1/Jet/xgl_utils.mm, line 24.

And the fact that I can successfully simulate the template application on the iPhone 6s Simulator.


I have been researching this for the past couple days like crazy, and I've only been able to discover that SKActions are the only .sks file that I'm able to create and open with the editor (still useless without the scene editor), and if I go click "Version Editor" (the icon with two arrows facing opposite directions), then view GameScene.sks, I can see that my file doesn't seem to be corrupted, as all the of the variables have the correct default values as my iMac.

Alright, I was able to fix the first issue by adding

NSKeyedUnarchiver.setClass(GameScene.self, forClassName: "GameScene")

right before the call to SKScene(fileNamed:), but the other issue regarding the GameScene.sks is still not resolved.

I have the same problem, in the beginning with Xcode 8 Beta 1, now with Xcode 8 Beta 2.


Tested on two iMacs, one new (2015), one rather old (2009). Both are running on OS X El Capitan. Tested on real hardware (iPhone 5S) and various simulator devices.


Adding


NSKeyedUnarchiver.setClass(GameScene.self, forClassName: "GameScene")


helped. However, this was not necessary for SpriteKit apps in Xcode 7 / iOS 9.


Even for a beta, I find it hard to believe Apple is shipping a SpriteKit template that is outright not working. There are rather few error reports like this one.


Anyone out there using Xcode 8 who can create a new Swift project (iOS/Game/SpriteKit) and actually run it without chaning anything?