SwiftUI + SpriteView = Gray screen

Xcode 13 beta 2, iOS 15 beta 2, the following code produces a gray screen (the SKScene GameScene.didMove(to:) never gets called):

import SwiftUI
import SpriteKit

// A simple game scene with falling boxes
class GameScene: SKScene {
    override func didMove(to view: SKView) {
        physicsBody = SKPhysicsBody(edgeLoopFrom: frame)
    }

    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        guard let touch = touches.first else { return }
        let location = touch.location(in: self)
        let box = SKSpriteNode(color: SKColor.red, size: CGSize(width: 50, height: 50))
        box.position = location
        box.physicsBody = SKPhysicsBody(rectangleOf: CGSize(width: 50, height: 50))
        addChild(box)
    }
}

// A sample SwiftUI creating a GameScene and sizing it at 300x400 points
struct ContentView: View {
    var scene: SKScene {
        let scene = GameScene()
        scene.size = CGSize(width: 300, height: 400)
        scene.scaleMode = .fill
        return scene
    }

    var body: some View {
        SpriteView(scene: scene)
            .frame(width: 300, height: 400)
            .ignoresSafeArea()
    }
}

I have no idea how to fix / workaround this issue.

Any thoughts?

Answered by Johnno in 684332022

iOS 15 beta 5 has fixed this issue!

I'm running into the same issue. Out of curiosity, I decided to run the project with My Mac (Designed for iPad) as the target simulator device, and it works perfectly fine there. I am going to try running it on my iPad and see if that does anything different.

My SpriteViews that worked well with iOS 14 just stopped rendering anything else than a background with iOS 15, both on iOS and catalyst. Reported since b1, including example project, still not working at all in b3.

I am having the exact same problem. I tried in a playground with a really simple scene (adding a yellow circle). It works if I display the view directly but SpriteView() in a swiftUI struct results in a blank gray screen.

Still an issue in Xcode 13 beta 4. :-/

Has anyone written a feedback for this? It seems like a common issue.

Yes, I wrote a Feedback with a sample project for beta1 - FB9197892. No response as of right now.

Accepted Answer

iOS 15 beta 5 has fixed this issue!

I'm still experiencing this from time to time with iOS 17. The first time it is loaded in the app, consecutive times are fine. However, it's not always, never in debug, and sometimes in production.

SwiftUI + SpriteView = Gray screen
 
 
Q