Parent 评估失败:变量不可用 - 雪碧套件

Parent failed to evaluate: variable not available - sprite kit

发生碰撞时出现错误。除了一个,我所有的碰撞都工作正常,这里的错误就是错误。完全没看懂是什么意思,是运行时错误,不是构建时错误

(SKNode) SpriteKit.SKNode = <parent failed to evaluate: variable not available>

代码:

func didBegin(_ contact: SKPhysicsContact) {
    let body1 = contact.bodyA.node as! SKSpriteNode
    let body2 = contact.bodyB.node as! SKSpriteNode
}

错误是什么意思,我该如何解决?

我这样做

func didBegin(_ contact: SKPhysicsContact) {

    let bodyA = contact.bodyA
    let bodyB = contact.bodyB

    guard let nodeA = bodyA.node as? SKSpriteNode,
          let nodeB = bodyB.node as? SKSpriteNode
    else {return}

    guard let parentNodeA = nodeA.parent,
          let parentNodeB = nodeB.parent
    else {return}

    //all your stuff
}