Unreal, like most game engines, has a failsafe for if the player falls out of the map and hits the KillZ. In Unreal this is called Fell Out Of World.
Internally the engine keeps track of your current height in the world, if you drop below that, the KillZ, the developer will teleport the player back into the world, usually to the last position you were in the world, but here we will be teleporting to a preset location.
How do we do this?
Before we get started, here’s what we want to change:
To start with you’ll need a C++ project, this currently cannot be overridden in blueprints.
Once you’ve got your C++ project you’ll need to create a new class based on ACharacter and call it whatever you want. Mine is BaseCharacter.
Adding the code to ABaseCharacter
Once you’ve got your custom ACharacter you’ll want to override FellOutOfWorld as seen in the image below.
Once you’ve got this you can go ahead and add this extra code to the .cpp file
This will now teleport the player back to the center of the world, plus 100 units up to account for the player capsuel size.
FellOutOfWorld exists in every actor as it is implemented in AActor. This means you can do this to anything that falls below the KillZ. The KillZ can be changed by going to the World Settings then changing the KillZ variable under World. By default, this is set very high, well…low, but it would take a while for your player to hit it, so adjust accordingly.