1

I am currently creating a 2D game with Swift SpriteKit and GameplayKit. I have a GameScene.sks file and a GameScene.swift file that is of type SKScene. Now I wanted to add a Component of type GKComponent. I created my component and added it to one of my SKSpriteNodes in GameScene.sks New Created Component

However after adding the Component to the SpriteNode in the Scene Editors Inspector the Scene is no longer loaded and the app shows only a grey screen.

enter image description here

Is this a known issue in XCode? Is there a way of bypassing this issue?

I have not uploaded any example code. The issue is reproducable by any new XCode Project (ios / Game) that supports SpriteKit and GameplayKit. Just add a class that is derived from GKComponent and add the class to the given helloLabel in the Scene Editor.

This is how the GameScene is loaded:

class GameViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        if let scene = GKScene(fileNamed: "GameScene") {
            if let sceneNode = scene.rootNode as! GameScene? {
                // This gets only executed when I remove the Component from the SKSpriteNode in the Scene Editor.
            }
        }
        ...
Oliver Koehler
  • 711
  • 2
  • 8
  • 24
  • 1
    Show your code that loads the scene – Knight0fDragon Feb 28 '20 at 14:11
  • 1
    I test and works fine, can try cloning this https://github.com/Maetschl/SpriteKitExamples/tree/master/ComponentTest ? For some reason your file it seems that it is not in the project. – Maetschl Feb 28 '20 at 23:56
  • Thanks @Maetschl, you are right. Your provided code works absolutely fine. I've also tried to add more new created components and even this worked fine. Now I will try with a new created project. – Oliver Koehler Feb 29 '20 at 07:44
  • @Maetschl: I've tried now on a different machine. Same result. I am not able to launch my app if the loaded GameScene has a SpriteNode where a GKComponent is added. Even with a new created GameScene.sks file it is not possible. I really wonder what you have done different to me? Cheers – Oliver Koehler Feb 29 '20 at 20:25
  • Now I've tried to add another GameScene to your project, changed to load the new GameScene via the GameViewController. Added a SKSpriteNode to the scene and added a component to the SpriteNode. -> Same result. Again a grey screen. Somehow it seems that the creation of sks files is corrupted. At least on my machines. – Oliver Koehler Feb 29 '20 at 20:56
  • I recommend you update XCode to the latest version. – Maetschl Feb 29 '20 at 21:48
  • I am already using the latest version Xcode Version 11.3.1 (11C504) – Oliver Koehler Mar 02 '20 at 06:36

0 Answers0