I'm coding a space invaders type app right now, and I recently ran into a really annoying fatal error that freezes my game. I'm trying to get a laser to take the enemy off of the screen, except as soon as the player, enemy, or laser come in-tact with each other, the game then freezes. I've tried force unwrapping it and everything, but nothing seems to work. Here is the area the error is at the moment: if body2.node == nil{ if ((body2.node!.position.y)) > self.size.height{
The error is in the line with if((body2.node. My error states: "Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value". FYI, I'm using the solo mission tutorial by Matt Heaney apps on YouTube to code.
Asked
Active
Viewed 40 times
-2
-
You are force unwrapping `body2.node` inside a condition where you already know that body2.node is nil : `if body2.node == nil`. Logic error. This crash is expected. Maybe you wanted to do the opposite? `if body2.node != nil` – Eric Aya Mar 25 '21 at 12:09