SKScene displayed as a SCNMaterial

Hi, I just wanted to display a SpriteKit Scene in a SCNPlane. So I set the the SCNMaterial contents to my SKScene, but instead of getting the scene I'm getting a grey plane. This is my code by the way:

var mainScene: SKScene {
    let scene = Game()
    scene.size = CGSize(width: 1024, height: 1024)
    scene.scaleMode = .resizeFill
    scene.backgroundColor = .purple
    scene.view?.backgroundColor = .purple
    scene.view?.allowsTransparency = false
    return scene
}



func initMainScene() -> SceneView {

    mainScene.view?.isPaused = false

    let scene = SCNScene()

    let mainSceneMaterial = SCNMaterial()
    mainSceneMaterial.normal.contents = mainScene
    mainSceneMaterial.isDoubleSided = true

    let planeGeometry = SCNPlane(width: 1, height: 1)
    planeGeometry.materials = [mainSceneMaterial]

    let plane: SCNNode = SCNNode(geometry: planeGeometry)

    let camera: SCNNode = SCNNode()
    camera.name = "Camera"
    camera.camera = SCNCamera()
    camera.position = SCNVector3(x: 0.0, y: 0.0, z: 4.0)

    let light: SCNNode = SCNNode()
    light.light =  SCNLight()
    light.light!.type = .omni
    light.position = SCNVector3(x: 1.5, y: 1.5, z: 1.5)

    scene.rootNode.addChildNode(camera)
    scene.rootNode.addChildNode(light)
    scene.rootNode.addChildNode(plane)

    return SceneView(
        scene: scene,
        pointOfView: scene.rootNode.childNode(withName: "Camera", recursively: false),
        options: []

    )
}

Here is the screenshot:

Also, my SpriteKit scene has touchesBegan and touchesMoved functions implemented, will those events still work if I embed the scene in the SCNMaterial?

Thanks very much 🙏

I have achieved to render the SKScene as the material of the SCNPlane, but the didMove function isn't being called, and if I set the material to a SKView, give it a frame size, and call presentScene passing my scene as the argument, the app crashes 😓

Hello,

It sounds like maybe you have found a solution to your original issue, but if not, I believe the problem is here:

    mainSceneMaterial.normal.contents = mainScene

Most likely you meant to set the diffuse.contents, not the normal.contents.

SKScene displayed as a SCNMaterial
 
 
Q