Created
January 17, 2024 15:59
-
-
Save ffreality/cfb1150f92819dbaf41b0df24bb1d083 to your computer and use it in GitHub Desktop.
Posses Local Player
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bool UCustomViewport::PossesLocalPlayer(const int32 PlayerId, const int32 ControllerId) | |
{ | |
UEngine* const REF_Engine = GameInstance->GetEngine(); | |
const int32 NumPlayers = REF_Engine->GetNumGamePlayers(this); | |
if (NumPlayers > PlayerId + 1 || ControllerId < -1) | |
{ | |
return false; | |
} | |
int32 PlayerControllerId = 0; | |
if (ControllerId == -1) | |
{ | |
PlayerControllerId = UGameplayStatics::GetPlayerControllerID(REF_Engine->GetGamePlayer(this, 0)->GetPlayerController(GEngine->GetCurrentPlayWorld())); | |
} | |
else | |
{ | |
PlayerControllerId = ControllerId; | |
} | |
REF_Engine->GetGamePlayer(this, PlayerId)->SetControllerId(PlayerControllerId); | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment