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.
Thanks for the reply! I really appreciate it! 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!