Skip to content

Instantly share code, notes, and snippets.

@ffreality
Created January 17, 2024 15:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ffreality/cfb1150f92819dbaf41b0df24bb1d083 to your computer and use it in GitHub Desktop.
Save ffreality/cfb1150f92819dbaf41b0df24bb1d083 to your computer and use it in GitHub Desktop.
Posses Local Player
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