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

I have the following code (SceneKit in Swift targeting on 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 that when 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'm not sure why this error occurs, but I'm trying to upload my file level.daeand add it to the scene. From what I see in the simulator (and device), it loads fine.

What to do to prevent an error message?

+4
source share
1 answer

- . levelScene node, . :.

let heroScene = SCNScene(named: "hero.dae")
if let heroNode = heroScene.rootNode.childNodeWithName("heroGroup", recursively: true) {
    scene.rootNode.addChildNode(heroNode)
}

:

for node in levelScene.rootNode.childNodes as [SCNNode] {
    scene.rootNode.addChildNode(node)
}
+7

Source: https://habr.com/ru/post/1548103/


All Articles