Cat Doesn't Seem to Hook

I’m currently using the Swift 3 version of the book and I can’t seem to get the cat to catch onto the hook. Using break points, I’ve determined that the problem lies in the code that detects the collision between the cat and the hook:

if collision == PhysicsCategory.Cat | PhysicsCategory.Hook
&& hookBaseNode?.isHooked == false {
hookBaseNode!.hookCat(catPhysicsBody:
catNode.parent!.physicsBody!)
}

hookBaseNode?.isHooked returns back as nil so the code within the if block never runs. I tried changing the if statement to check for nil instead and the cat hooks but then the game crashes.
Thank you for any help.

If hookBaseNode?.isHooked is returning nil instead of false, then hookBaseNode is nil and hookBaseNode! will crash because you’re force-unwrapping a nil optional.
Can you make sure hookBaseNode isn’t nil? Is it correct in the code and in the .sks file?

1 Like

Ok , so I checked the .sks file and compared it to the final version and found that the hook base was not linked to the HookBaseNode class. I fixed that but now I’m getting a crash that says
“unexpectedly found nil when unwrapping an optional value.” I’ve tried comparing my code to the final version to weed out the issue and it seems I still can’t seem to find where the disconnect is. Anyone have any ideas of where to look?
****EDIT: Found the problem. The hook base node was named “hookBas” instead of “hookBase”. >_<
Thank you for taking the time to reply, though!