Why does this line crash editor only when play is started?

In my vehicle pawn file in tick i have this line of code


float fScore = GetPlayerState()->GetScore();

this line causes a crash if it is in tick why? I have this line in few other areas and it works fine, why in tick is it causing a crash.

@ Epic, why is score a float? and not an int32? i have never heard of 1.5 kills or 1.5 laps. Just curious why it is a float?

If you want to experience this crash. Add the above line into the CurrentVehiclePawn::UpdateHUDStrings() function, which is called by tick. Start the editor then hit play.

Probably because your GetPlayerState is returning a nullptr. You should always code defensively (e.g., check for nullptrs).



float fScore = 0.0f;
if (GetPlayerState())
{
    fScore = GetPlayerState()->GetScore();
}


And that value is a float because they likely thought they would need a float at the time. You can always make edit your PlayerState and make it an int. Epic went with what works for them, not necessarily what they think will work for everyone else.

Thanks for the fix. After i changed the code and set the if and set the logs right. The tick runs 4 times before it finds a working Getplayerstate(); That is why it was crashing. It was a nullptr for the 1st 3 runs thru tick. 4th time thru we get a player state. Thanks again.