Reset player controller

Normally, when loading a new level the player controller is reset to default. Is there a way to reset it manually? For example, between streaming levels where the persistent level doesn’t change, but you still want to reset/restart the controller to default state?

I tried destroying the controller but this seems to do nothing. Also I tried removing the player but the game crashed. Also restarting the player does nothing.

I actually want to use the same player controller, but a different instance of it. So when I unload the streaming level I want to destroy the current player controller and create a new one OR reset the current one to it’s default state.

I managed to destroy it using C++ but this crashes the game.

I don’t know if this is what you are looking for but you can set different controllers for different levels on ‘world settings’.

I found a solution:

https://api.unrealengine.com/INT/API/Runtime/Engine/GameFramework/AGameModeBase/SwapPlayerControllers/index.html

I exposed it to BP like this:

void UTheBirdcageCPPFunctionLibrary::SwapPlayerController(APlayerController * OldPC, APlayerController * NewPC, AGameModeBase * GameMode)
{
GameMode->SwapPlayerControllers(OldPC, NewPC);

return;
}

Then spawn a new player controller with the ‘spawn actor from class’ node and perform this function on it.

there is a clunky way: GetClassDefaults function. You can copy all the values from that to the current playercontroller instance.

Thanks for sharing! Where do you call this from / when?

Called it just before or after streaming the new level, in the game mode.

1 Like