I have the following code (SceneKit in Swift targeting iOS):
let scnView = self.view as SCNView
let scene = SCNScene()
let levelScene = SCNScene(named: "level")
scene.rootNode.addChildNode(levelScene.rootNode)
scnView.scene = scene
scnView.backgroundColor = UIColor.grayColor()
scnView.allowsCameraControl = true
scnView.showsStatistics = true
The problem is, at scene.rootNode.addChildNode(level.rootNode)
I get the following error in the console:
[SCNKit ERROR] removing the root node of a scene from its scene is not allowed
I am not sure why this error is coming up, but I am trying to load my level.dae
file in and add it to the scene. From what I can see in the simulator (and device), it loads fine.
What should I do to prevent the error message from occuring?
Root nodes are special -- they can't be un-parented from their scenes and moved into new scenes. You need to pull a child or descendant node out of your levelScene
to move into your game scene. e.g.:
let heroScene = SCNScene(named: "hero.dae")
if let heroNode = heroScene.rootNode.childNodeWithName("heroGroup", recursively: true) {
scene.rootNode.addChildNode(heroNode)
}
or move them all:
for node in levelScene.rootNode.childNodes as [SCNNode] {
scene.rootNode.addChildNode(node)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With