Bug Report: Crash when changing TargetArmLength in C++

Hello, just to report a bug

I added a Custom C++ PlayerController class and made a Blueprint inheriting of this class, This BP class is the PlayerController asgined to the player.

I made a Getter for the CameraBoom in the player class

in the C++ playercontroller header I have a reference to the player


class APlayerClass *Player; 

then in C++ PlayerController Begin Play…


 Player = static_cast<APlayerClass*>(UGameplayStatics::GetPlayerCharacter(this, 0));

InitialCameraBoomLenght = Player->GetCameraBoom()->TargetArmLength;

And then in the C++ PlayerController Tick I have this lines


if (Player) {
          Player->GetCameraBoom()->SetWorldRotation(FRotator(CameraBoomDesiredPitch, CameraBoomDesiredRotation, 0));
}

Everything compiles well and run as I exepected, but If I try to open the PLAYERCONTROLLER BLUEPRINT inherithing this C++ PlayerController Class the system Crashes, If I comment the line changin the value of cameraboom the PlayerController Blueprint opens normaly

the same error occurs with this line


if (Player) {
	Player->GetCameraBoom()->TargetArmLength = InitialCameraBoomLenght + CameraBoomDesiredLenght;
}

Looks like you have accessed the Null Pointer.
Have you debugged?
Or try to return the function, when Player is not exist.

Your cast is wrong. You should be using the UE4 Cast function.



Player = static_cast<APlayerClass*>(UGameplayStatics::GetPlayerCharacter(this, 0));


Should be:



APlayerClass* Player = Cast<APlayerClass>(UGameplayStatics::GetPlayerCharacter(this, 0));


I almost guarantee you that this is a nullptr / access violation crash.