What I'm try to do, is replicate some digital instrument gauge ...using Spritekit..
On my project I have to use a SpriteKit Scene as material for Scenekit SCNnode.
In order to do that I create a sub class of SKscene and and apply it as "material.diffuse.contents" of the SCNNode.
all working fine, I can see my SKscene as material of the SCNNode.
Here the issue:
I try to animate/replicate the correct indication of the instrument based of some value my app received from other source.
To do so, i decide to use the SKsceneDelegate and use the method "update(_ currentTime: TimeInterval)"
simply the update method look for the sknode of the green needle "fulcro" remove it , and make a new line calculating the angle and new coordinate for the new line.
override func update(_ currentTime: TimeInterval) { guard let fulcroToRemove = self.childNode(withName: "fulcro") else {return} fulcroToRemove.removeFromParent() // issue here... let fulcro = SKNode() fulcro.name = "fulcro" fulcro.position = CGPoint(x: 300, y: 260) let line = makeLine(startPos: CGPoint(x: 0, y: 0), endPos: getCoordinate(angleDeg: getCurrentEGT()), name: "EGT_LINE") fulcro.addChild(line) self.addChild(fulcro) }
... if I try this SKscene itself in a project only with Spritekit all working fine.. I can see my needle increase the value correctly when the data source increase.
But if use the same SKscene as material of SceneKit getting the following error:
look like I'm removing something not correctly .. and I can see fulcroToRemove.removeFromParent() is the line trigger the error.
But why ??How I can remove the line to avoid the crash?