Download

Nullptr when trying to change member variable from a different function.

Hey all,

I’m trying to change a bool value in a actor component c++ file in the Character cpp file. When I do this, my engine crashes with a nullptr. I know I’m likely missing something simple, but I’m clearly missing something.

Thanks for the help in advance!

Component header:


public:

bool BActivateMovement = false; void SetBActivateMovement(bool bBActivateMovement) { BActivateMovement = bBActivateMovement; 

Character header:


class AObjectMovementTestCharacter : public ACharacter
{
GENERATED_BODY()
public:
UPROPERTY()
class UMoveAndRotate* MyTrigger;
void TriggerMovementAndRotation();
etc....

Character c++

included the header for the component


void AObjectMovementTestCharacter::SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) { // Set up gameplay key bindings check(PlayerInputComponent); PlayerInputComponent->BindAction("Jump", IE_Pressed, this, &ACharacter::Jump); PlayerInputComponent->BindAction("Jump", IE_Released, this, &ACharacter::StopJumping); PlayerInputComponent->BindAction("Movement", IE_Pressed, this, &AObjectMovementTestCharacter::TriggerMovementAndRotation); etc.....


void AObjectMovementTestCharacter::TriggerMovementAndRotation() { MyTrigger->bActivateRotation = true; //Remove this line to unbreak the code. }