I’m learning unreal engine networking and i ran into a confusing scenario.
My ACustomGameModeBase which extends from AGameModeBase overrides void PostLogin(APlayerController*) . Inside i do a simple check if I’m running on server or client:
if(GetNetMode() == ENetMode::NM_ListenServer)
{
UE_LOG(LogTemp, Log, TEXT("PostLogin running on server"));
}else
{
UE_LOG(LogTemp, Log, TEXT("PostLogin player running on client"));
}
I run this with one listening server and one client.
Now, since every tutorial/documentation/etc. claims that GameModes instances are not created on clients, I expect this function to print 2x “Running on Server”, once for each connected client. But when I run this I actually get one “running on server” and one “running on client”.
So my question is: Does an instance of GameModeBase exist on clients as well? Or maybe the GetNetMode() function returns something else then NM_ListenServer even though its being run on the server?
Any explanations would be appreciated.
PS. I’ve tested it with a couple of overridable functions from here: GameModes and so far only void BeginPlay() runs once on the server. Other functions are called twice: once on server and once on client.
So I did some more debugging and I realised what the problem is.
When running from the editor with “Listen Server” mode and 2 clients, the client game isntance is created first before the server. The client thinks it is in standalone mode and runs PostLogin() on it’s GameModeBase instance. Then after the server is launched the client connects normally, but the damage has already been done.
Is there a way to force the clients to launch in an “online mode” for debugging a single level.
I can see how this wouldn’t be an issue if i had a menu screen or a Connect button somewhere but maybe there’s a simple way i don’t know about.
Edit: It seems that PostLogin() is a client-side function. Is there an equivalent that runs whenever a new player successfully logs in to the game on the server-side GameModeBase object?
I realize I am a bit late with this reply and I don’t know if you already fixed the issue but i think you’re barking up the wrong tree: there are no game modes on the clients when you are running a multiplayer instance. The game mode exists only on the server and the PostLogin function is called whenever a new player controller has been created.
I’m running 4 players on a listen server, the postlogin only gets called once, from the server. I thought it gets called when each player gets into the game?