Post

Replies

Boosts

Views

Activity

Help needed. Fatal error:Unexpectedly found nil while unwrapping an Optional value
Hey, Thank you for taking a look at this and for your help in advance..... I'm new to this so sorry if I haven't posted this is in the correct way. I am receiving an error on an IF statement in a didBegin() function in my game when I run it. The game builds and runs ok but on occasion it crashes and I get this error. Usually it happens when there are lots of nodes on the screen making contact with other nodes. The error is on the IF statement line 25 on the code below. I've been trying to fix this but so far no luck so I'm hoping someone on here with more experience can help me out. Thank you MasterChief: Spartan G14 Error message : Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value Swift - Xcode version Version 11.1 (11A1027)  func didBegin(_ contact: SKPhysicsContact) {         var bodyOne:SKPhysicsBody         var bodyTwo:SKPhysicsBody                  if contact.bodyA.categoryBitMask < contact.bodyB.categoryBitMask {             bodyOne = contact.bodyA             bodyTwo = contact.bodyB         }else{             bodyOne = contact.bodyB             bodyTwo = contact.bodyA         }                  if (bodyOne.categoryBitMask &amp; playerWeaponCategory) != 0  &amp;&amp; (bodyTwo.categoryBitMask &amp; enemyCategory) != 0 {                     playerWeaponHitEnemyUnit(playerWeaponAsset: bodyOne.node as! SKSpriteNode, enemyAsset: bodyTwo.node as! SKSpriteNode)                  }              }  
3
0
2.4k
Jun ’20