Hello everyone!
I am having a problem with this area of the course. For some reason, after I added the lose screen functionality, my GameMode broke. Now GameMode is always equal to nullptr and it makes respawning and the lose screen not work.
Here is my code for the TakeDamage function:
float AShooterCharacter::TakeDamage(float DamageAmount, FDamageEvent const& DamageEvent, AController* EventInstigator, AActor* DamageCauser)
{
float DamageApplied = Super::TakeDamage(DamageAmount, DamageEvent, EventInstigator, DamageCauser);
DamageApplied = FMath::Min(Health, DamageApplied);
Health -= DamageApplied;
UE_LOG(LogTemp, Warning, TEXT("Health Remaining: %f"), Health);
if (IsDead())
{
GetCapsuleComponent()->SetCollisionEnabled(ECollisionEnabled::NoCollision);
UWorld* World = GetWorld();
if (World != nullptr)
{
AShooterGameModeBase* GameMode = World->GetAuthGameMode<AShooterGameModeBase>();
if (GameMode == nullptr)
{
UE_LOG(LogTemp, Error, TEXT("ShooterCharacter expected a GameMode but recieved none!"));
}
else
{
GameMode->PawnKilled(this);
}
}
else
{
UE_LOG(LogTemp, Error, TEXT("ShooterCharacter expected a world but recieved none!"))
}
DetachFromControllerPendingDestroy();
}
return DamageApplied;
}
I am always getting the “ShooterCharacter expected a GameMode but recieved none!” error.
Any help is very appreciated!
ViralDisorder