Download

Trouble getting local player controller on clients?

This is incredibly stupid but at the same time, I can’t figure it out. I know player controllers only exist on the client, but I don’t understand why I can’t get the controller on the clients themselves either. I have the following code in the BeingPlay() of my Character class :

myController = Cast<AFPSGameController>(GetController());

if (myController) {
FString msg = “Controller fetched in " + GetName();
UKismetSystemLibrary::PrintString(this, (TEXT(”%s"), *msg));
}

I would expect this code to print 1 line each on the instances. What I mean is if I start 4 instances of the game (1 server, 3 clients), I thought each client would be able to successfully get their own player controllers. So suppose Char_1, Char_2, Char_3, and Char_4 get spawned for server, client 1, client 2, and client 3 respsectively, Char_1 would successfully fetch and print the message on server, Char_2 would print the message on client 1, Char_3 on client 2, Char_4 on client 3.
But the logs being printed look like this :

LogBlueprintUserMessages: [EBaseCharacter_C_1] Server: Controller fetched in EBaseCharacter_C_1
LogBlueprintUserMessages: [EBaseCharacter_C_0] Client 3: Controller fetched in EBaseCharacter_C_0
LogBlueprintUserMessages: [EBaseCharacter_C_0] Client 1: Controller fetched in EBaseCharacter_C_0
LogBlueprintUserMessages: [EBaseCharacter_C_0] Client 2: Controller fetched in EBaseCharacter_C_0

Really sorry for being a noob but I’m having a tough time with this. Any help would be appreciated.

This looks correct to me. Characters and Controllers will not share the same object names accross different instances of the running game so ID’ing the object by it’s name isn’t a reliable way to identify it.

E.g, The Server (assuming it’s a listen server in this case) will have four controllers - it will create it’s own controller first (suffix _0) - then client controllers (suffix _1 - _3)

Clients will only ever have their own controller. Since it will be the first controller, they will all be suffixed with _0. Characters may be received in any order, depending on which one replicates first.

@TheJamsh You’re right. Added a IsLocalController() check and got the same results. Thanks for the help!