Respawn on FellOutOfWorld

I am extending the FPS Project C++ tutorial sample… I want to restart the player at the original player start position if they hit the killz. I want to do this in C++ (not BP).

In AFPSCharacter I override FellOutOfWorld and called:

GetWorld()->GetAuthGameMode<AFPSProjectGameMode>()->RestartPlayer(Controller);

It doesn’t work though (the player remains at the point where it hit the killz).
It seems from debugging like the pawn gets NULL’d out by the ClientRestart function.

Does anyone know the proper way to restart the player at the player start if they hit the killz height specified in world properties?

You could make a volume actor and simply use an OnHit method call. If it’s true then SetActorLocation to the vector or whatever logic you planned on using.

I’d recommend this way since you could place the volume anywhere which could account for a variety of scenarios.

It sounds like a good idea. In the end I got it to do what I want using:

void AFPSCharacter::FellOutOfWorld(const class UDamageType& DmgType)
{
	//Super::FellOutOfWorld(DmgType);

	//Teleport back to the player start position.
	APlayerController* PC = Cast<APlayerController>(Controller);
	if (PC)
	{
		AActor* StartSpot = GetWorld()->GetAuthGameMode<AFPSProjectGameMode>()->FindPlayerStart(PC);
		if (StartSpot)
		{
			SetActorLocation(StartSpot->GetActorLocation());

			// set initial control rotation to player start spot rotation
			PC->ClientSetRotation(PC->GetPawn()->GetActorRotation(), true);
			FRotator NewControllerRot = StartSpot->GetActorRotation();
			NewControllerRot.Roll = 0.f;
			PC->SetControlRotation(NewControllerRot);
		}
	}

	GetWorld()->GetAuthGameMode<AFPSProjectGameMode>()->RestartPlayer(Controller);
}

Its not exactly what I want as actually I want to Destroy() the player actor and this does not do the destroy. If anyone knows the proper way to Destroy() the player on Killz and Respawn ondestroy (via C++) it would be very helpful to add to this thread.

Hi,

I do something like:

void AMyPawn::TornOff()
{
	Super::TornOff();

	SetLifeSpan(1.0f);
}

void AMyPawn::FellOutOfWorld(const class UDamageType& dmgType)
{
	Super::FellOutOfWorld(dmgType);

	bReplicateMovement = false;
	bTearOff = true;

	DetachFromControllerPendingDestroy();

	// Hide and disable the current pawn
	TurnOff();
	SetActorHiddenInGame(true);
	SetLifeSpan(0.1f);
}

Additionally this also needs:

void AMyPlayerController::UnFreeze()
{
	ServerRestartPlayer();
    // or only:
    // GetWorld()->GetAuthGameMode()->RestartPlayer(this);
}

It seems that ServerRestartPlayer will call RestartPlayer for you. I got this to work, so in case it doesn’t I might have forgotten to copy something important :slight_smile: Also, I’m just a UE noob! So if this may have some unwanted side effects, or if it’s otherwise subobtimal, I would love to hear about it! Oh yea, and I somehow got this from the “Vehicle Game” example at the “Learn”-tab of the laucher.

This worked well for me, thank you!