SpriteKit game crashes when two SKPhysicsContacts are detected

∥☆過路亽.° 提交于 2019-12-06 05:13:45

Sounds like a duplicate of Optional unwrapping SKPhysics error

SK is generating multiple contact events for one actual contact and so didBegin() is being called multiple times.

On the first call to didBegin you handle the contact and remove one or mode nodes etc, and on the second call to didBegin (with the same contact: argument) the nodes you removed are now nil, so when you try to remove or reference them you get a crash.

There are several ways to handle this such as adding the nodes to be removed to a set and then removing them in didFinishUpdate() or checking if a node is nil and then returning if it is etc.

Trying to get SK to NOT generate the multiple contacts currently seems unachievable.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!