How to Get Player Controller on Listen Servers?

Hello,

I’m trying to get the player controller on a listen server. Unfortunately, the IsLocalPlayerController() function returns true for every controller on the server, since it owns all of them, so I’m having trouble finding the listen server.

I’m trying to use this code to get the hud of each player (and display some information on the screen to aid debugging):

When executed on listen server side, GameplayStatics’ GetPlayerController(0) should return the playercontroller of the server host always

I see this repeated a lot but is it actually true? (honest question)

If we look at the engine source, on the server APlayerController uses a bool var bIsLocalPlayerController. This is set during AGameModeBase::SpawnPlayerControllerCommon with this:

if (InRemoteRole == ROLE_SimulatedProxy)
{
	// This is a local player because it has no authority/autonomous remote role
	NewPC->SetAsLocalPlayerController();
}

So in theory only the listen host player controller should be tagged as local, because the remote ones (clients) have ROLE_AutonomousProxy.

I made a very simple example, printing whether a PC is local or not from the listen host perspective, on AGameMode::PostLogin.

The result:

Are there any situation where this wouldn’t be the case? I’m not an expert in networking and right now I’m using IsLocalPlayerController to detect the listen host, but my project hasn’t shipped so I might discover some issues along the way :melting_face: