SpriteKit - SKShapeNode from a loaded SKScene not rendered

91 Views Asked by At

I'm loading a SKScene from a file. In it, a SKShapeNode that I can see on the screen. But if set the "custom class" to a class like TestNode below, the ShapeNode won't be rendered: implementing init with coder and debugging, I can see that the .scene is nil, even if in the "attributes editor" in Xcode, the parent is set to the Scene. I can even get userData I set on the Node. The node is initiated as isPaused = true, setting it to false doesn't help.

public class TestNode: SKNode {
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
}

Any idea why the .scene property is nil?

1

There are 1 best solutions below

0
Eternam On

Turned out that the custom class has to be of the exact same class as the node added in the scene editor.

So if you had a SKSpriteNode in the scene (.sks file) and set its custom class property, that custom class must also be a SKSpriteNode, it can't just be a SKNode.