Bug Or Something Else? Hard Crashing In the Editor. Refactoring Aiming Component

Hey guys, I’m currently on lecture 168. I’m not sure if this is a bug or not though.

My question is regarding this chunk of code here. On line 24 and 25 of my code, if I add these two lines and take out the ensure check on line 26, the Unreal Editor is able to compile fine and with no errors. I’m able to play as well with both AI and Player Aiming working and the turret and barrel following. Firing is not working, but that’s separate.

An oddity though is that if I try to open the TankPlayerControllerBP, the editor hard crashes. Could you guys see if you can recreate this on your guy’s end? I’m not completely sure if it’s something with my code or what.

As you see it in the screenshot currently, if I try to go and open TankPlayerControllerBP, it works fine and I don’t crash. It’s only after adding line 24 and 25 that I get a hard crash if TankPlayerControllerBP is open.

This is addressed in the next video.

But as a hint: in the blueprint editor you don’t have a possessed pawn, so GetPawn()->FindComponent will crash as you point to a nullptr.

Try to get the GetPawn() check before adding the AimingComponent :slight_smile:


:+1: Fail Faster - there is no instant win :+1:
Twitter: @GamedevCala - Blog: nerd-time.com - Twitch: GamedevCala

Thanks for the reply! I really appreciate it! :smiley: I’m just curious though on the reasoning for the crash. I put an extra ensure check after making a variable just solely equal to GetPawn(). Is it that we’re not able to get a possessed pawn immediately?

GetPawn() returns a nullptr, if it can’t find a possessed pawn. The blueprint editor never has a possessed pawn, as it is not a ‘real’ instance inside the game but for editing purposes. The check should be before the first use.

In your code you directly try to access the FindComponentByClass method of the object returned by “GetPawn()” (line 24). This crashes the blueprint editor, because it is pointing to null.

Agreed, all you had to do was move your if(!ensure(GetPawn())) line before those other two lines. Always take a top-down approach when performing checks like this. Gotta check the pawn before you try to access things from it! :grin:

Privacy & Terms