How do I remove a second splitscreen player?

I have two player local splitscreen basically working; in the level blueprint of my 2 player map I use Create Player (Index 1) to create a second player. However, upon returning to the main level or other levels, the second player is still present, even though I only want a single player. The debug console command “DebugRemovePlayer 1” command works perfectly, but I see no way to call something like that in blueprint. Any help would be very appreciated. Thanks!

Actually, I have a stupid way to solve this problem: there’s a blueprint node for “Execute Console Command” so I used it to execute “DebugRemovePlayer 1”. This removes the player exactly how I want to. Using string concatenation and a for loop I’d imagine anyone who needs to remove x many local players from their game will be able to do so, but I can’t imagine this is good practice. I’m leaving this as unresolved until someone comes with a less ugly solution.

Since people who work on the engine read these sometimes, why have a “Create Player” blueprint node if you’re not going to have a corresponding “Remove Player” one? It seems awfully inconvenient.

I’ve successfully used the DebugRemovePlayer console command to remove players, but it doesn’t work in a Shipping Build (probably because the Console isn’t available in Shipping builds).

I really need to know how to remove created players, either in Blueprint or C++. So if anyone has any leads on how to do this, I’d really appreciate it. Thanks.

I was able to remove extra players with the following C++ method, which was originally posted in this Question: How do I remove a split-screen player? - Multiplayer & Networking - Epic Developer Community Forums

What it does it checks for, and removes from the game, all local splitscreen players except the primary player. The easiest way to get this into Blueprint is to create a C++ class that is a subclass of Blueprint Function Library, and add this method to it:

void UBP_FuncLib::RemoveSplitscreenPlayers()
 {
     const int32 MaxSplitScreenPlayers = 4;
     ULocalPlayer* PlayersToRemove[MaxSplitScreenPlayers];
     int32 RemIndex = 0;
 
     for (FConstPlayerControllerIterator Iterator = GEngine->GameViewport->GetWorld()->GetPlayerControllerIterator(); Iterator; ++Iterator)
     {
         // Remove only local split screen players
         APlayerController* Controller = *Iterator;
         if (Controller && Controller->IsLocalController() && !Controller->IsPrimaryPlayer())
         {
             
             ULocalPlayer* ExPlayer = Cast<ULocalPlayer>(Controller->Player);
             if (ExPlayer)
             {
                 PlayersToRemove[RemIndex++] = ExPlayer;
                 Controller->PawnPendingDestroy(Controller->GetPawn());
             }
         }
     }
 
     for (int32 i = 0; i < RemIndex; ++i)
     {
         
         GEngine->GameViewport->RemovePlayer(PlayersToRemove[i]);
     }
     
 }

Used deprecated functions, please take a look at this solution, but its as of now broken:

In your answer, you say the code isn’t working. Have you resolved the issue?

Hi, How would I select a specific player instead removing all players. What C++ code would I need?

I would imagine something like only running the for loop only for the indices of the players you want to remove; but I’m not entirely sure, as I’ve only ever removed everyone but the main player.

We are currently using 4.5 on a game and this definitely works. Thanks Jonathan!

This code originally posted here that removes all players except the main player actually uses deprecated code.

As of 4.4, GameViewport::RemovePlayer was deprecated. So I updated the method to use the new RemoveLocalPlayer method in UGameInstance; here is the updated code; note the new UGameInstance* argument passed in, and how it’s used in the last for loop:

.h file code:

// Removes local splitscreen players, with Player Index 1 to 3, from the game, leaving only the primary player
	UFUNCTION(BlueprintCallable, Category = "Multiplayer")
		static void RemoveLocalSplitscreenPlayersFromGame(UGameInstance* CurrentGameInstance);

.cpp file code:

void UBP_FuncLib::RemoveLocalSplitscreenPlayersFromGame(UGameInstance* CurrentGameInstance)
{
	const int32 MaxSplitScreenPlayers = 4;
	ULocalPlayer* PlayersToRemove[MaxSplitScreenPlayers];
	int32 RemIndex = 0;

	for (FConstPlayerControllerIterator Iterator = GEngine->GameViewport->GetWorld()->GetPlayerControllerIterator(); Iterator; ++Iterator)
	{
		// Remove only local split screen players
		APlayerController* Controller = *Iterator;
		if (Controller && Controller->IsLocalController() && !Controller->IsPrimaryPlayer())
		{
			ULocalPlayer* ExPlayer = Cast<ULocalPlayer>(Controller->Player);
			if (ExPlayer)
			{
				PlayersToRemove[RemIndex++] = ExPlayer;
				Controller->PawnPendingDestroy(Controller->GetPawn());
			}
		}
	}

	for (int32 i = 0; i < RemIndex; ++i)
	{
		//GEngine->GameViewport->RemovePlayer(PlayersToRemove[i]); // GameViewport::RemovePlayer was Deprecated in 4.4
		CurrentGameInstance->RemoveLocalPlayer(PlayersToRemove[i]);
	}
}

Check out the new answer I posted for updated code to avoid using a deprecated method.

this worked perfectly, thanks!

As of now (ver. 4.13), there is a blueprint node for Remove Player. Use it after Create Player to remove the player and split screen.

Thank you kindly! Helped out perfectly!