Sleepless nights - why score won't update

Thanks HammelGammel - It crashes - terribly. I created three functions in the HUD class, and call these functions from within the AMyActor class after getting a reference to the AMyHUD class. See code below:

The AMyActor.cpp Class



void AMyActor::OnHit_Implementation(AActor *OtherActor, UPrimitiveComponent *OtherComponent, int32 OtherBodyIndex, bool bFromSweep, const FHitResult &SweepResult)
{
	if (Cast<AsideScroller1Character>(OtherActor) == nullptr)
	{
		return;
	}
	this->Destroy();
	
	APlayerController *pPlayerController = GetWorld()->GetFirstPlayerController();
	if (pPlayerController) {
		AMyHUD *hud = Cast<AMyHUD>(pPlayerController->GetHUD());
	
		hud->DecrementScore();
		hud->PrintScores();
	}
}


The AMyHUD.cpp class - the PrintScores function hasn’t changed from the original. I’ve set the initial value of nLivesRemaining = 10 in the AMyHUD constructor function:




void AMyHUD::DecrementScore() {
	nLivesRemaining -= 1;
}




AMyHUD::AMyHUD()
{
	nLivesRemaining = 10;
}

void AMyHUD::DecrementScore() {
	nLivesRemaining -= 1;
}

void AMyHUD::PrintScores()
{
	FString Message;
	if (nLivesRemaining < 0) {
		Message = "You have No more lives remaining";
		GEngine->AddOnScreenDebugMessage(0, 5.f, FColor::Cyan, FString(Message));
	}
	else
	{
		GEngine->AddOnScreenDebugMessage(0, 5.f, FColor::Cyan, FString::Printf(TEXT("You have %d lives remaining"), nLivesRemaining));
	}
}