GameMode = nullptr

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.

image

Any help is very appreciated!
ViralDisorder

Is your KillEmAllGamemode a child of AShooterGameMode?

Thank you so much for responding! I just checked and I found out it was not a child. That fixed the problem. Thanks!

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms