Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SCNKit ERROR removing the root node of a scene from its scene is not allowed

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?

like image 437
BytesGuy Avatar asked Jul 11 '14 17:07

BytesGuy


1 Answers

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)
}
like image 192
rickster Avatar answered Sep 17 '22 10:09

rickster