First player controller is crashing unreal

So i posted my code and the error crash screen. I see on the first line that the GetFirstPlayerController() function is crashing unreal engine and I do not know why. i added in the nullptr to check before assigning the pawn however still it crashes.

266443-screen-shot-2019-01-24-at-10228-pm.png

Can you provide more code, where do you calling it? And copy paste insted of doing screenshots. Also did you tried to build this with editor close so no hot reload don’t happen, since it seems to crash on hot reload

This may or may not be the cause of crash (Probably need to see more code than you’ve provided to be sure), but there is some bad logic in your second screenshot.

You are saying:
if (()->GetFirstPersonController() == nullptr)
{
MainPlayer = ()->GetFirstPersonController()->GetPawn();
}

The problem with that your checking that GetFirstPersonController IS nullptr (==) where as I expect you want IS NOT null ptr (!=). In your version, you’ll pass the check and then try and assign MainPlayer if firstpersoncontroller is null, but then you immediatly try to GetPawn from what we know is a nullptr, and hence will crash.