In C++, you are able to remove players via the gameInstance, but in Blueprint there is currently no node to do so.
Check the answer section of a proposed fix for this of me.
I hope to see this in Unreal Engine at some point.
Cheers.
In C++, you are able to remove players via the gameInstance, but in Blueprint there is currently no node to do so.
Check the answer section of a proposed fix for this of me.
I hope to see this in Unreal Engine at some point.
Cheers.
EDIT: As of now it seems to be not working… for now im going to use this deprecated (!) code instead: How do I remove a second splitscreen player? - Blueprint - Epic Developer Community Forums
Add a new Blueprint Function library, with the name “UBP_FuncLib” and add this code for the cpp file :
#include "CarCarCar.h"
#include "UBP_FuncLib.h"
#include "Runtime/Engine/Classes/Engine/GameInstance.h"
void UUBP_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());
}
}
}
UWorld* currentWorld = GEngine->GetWorld();
UGameInstance* gameInstance = currentWorld->GetGameInstance();
for (int32 i = 0; i < RemIndex; ++i)
{
gameInstance->RemoveLocalPlayer(PlayersToRemove[i]);
}
}
For the .h file add this code:
#pragma once
#include "Kismet/BlueprintFunctionLibrary.h"
#include "UBP_FuncLib.generated.h"
/**
*
*/
UCLASS()
class CARCARCAR_API UUBP_FuncLib : public UBlueprintFunctionLibrary
{
GENERATED_BODY()
public:
UFUNCTION(BlueprintCallable, Category = "CustomLibrary")
static void RemoveSplitscreenPlayers();
};