I am setting my still small-ish project up for multiplayer.
I managed to create and join a LAN session mostly following this quite dense Youtube-Video, which I deem the best intro into C++ multiplayer for Unreal Editor.
I use a .bat script to launch my game twice on my PC, with
[OnlineSubsystem]
DefaultPlatformService=NULL
in “Config/DefaultEngine.ini” for Local Access Network/LAN.
My launch script looks like this:
"F:\ue\UE_5.0\Engine\Binaries\Win64\UnrealEditor.exe" "F:\ue\projects\MurderInSpace\MurderInSpace.uproject" -game -ResX=800 -ResY=600 -WINDOWED -WinX=0 -WinY=20 -log
A lot things do work:
My game opens in two separate windows, I click through my UI to host a game and a the map is loaded, i.e. using this line from the above YouTube-Tutorial:
GetWorld()->ServerTravel("/Game/Maps/spacefootball?listen");
I then click through my UI in the second window where my session search shows one result, I can join and the map is loaded as expected, too. This time using this line, differing a bit from the same tutorial:
ClientTravelToSession(LPC.GetLocalPlayer()->GetControllerId();
However, now only the Pawn of my host windows receives mouse and keyboard input. The Pawn in the client window can’t be moved. Also, in the host window there does spawn another pawn, but in the client window I sometimes see one, sometimes two pawns inconsistent with the locations of the pawns in the host window.
A couple of static mesh actors are behaving as if both host and client would load them independently rather than them being replicated.
I don’t think it’s a mere replication issue. My PlayerController is acting unexpected, with only one of the two windows processing any input.
Also, I have a couple of errors showing up in the Log that might point to some fundamental issues in my code:
Host log output:
[2022.10.25-22.03.25:378][275]LogUObjectGlobals: Warning: Gamethread hitch waiting for resource cleanup on a UObject (SplineMeshComponent /Game/Maps/spacefootball.spacefootball:PersistentLevel.BP_CharacterInSpace_C_0.SplineMesh.SplineMesh39) overwrite took 0.00ms. Fix the higher level code so that this does not happen.
0.25-22.03.36:758][888]LogNet: Login request: ?Name=DESKTOP-4092S33-F23D06FB4231FF9CE858F798131D01DB userId: NULL:DESKTOP-4092S33-F23D06FB4231FF9CE858F798131D01DB platform: NULL
[2022.10.25-22.03.36:758][888]LogNet: Warning: BP_MyGameMode_C /Game/Maps/spacefootball.spacefootball:PersistentLevel.BP_MyGameMode_C_0: PreLogin
unique net id: DESKTOP-4092S33-F23D06FB4231FF9CE858F798131D01DB
[2022.10.25-22.03.36:786][889]LogNet: Client netspeed is 100000
[2022.10.25-22.03.37:129][930]LogNet: Join request: /Game/Menu/spacefootball_mainmenu?Name=DESKTOP-4092S33-F23D06FB4231FF9CE858F798131D01DB?SplitscreenCount=1
[2022.10.25-22.03.37:130][930]LogNet: Display: BP_MyPlayerState_C /Game/Maps/spacefootball.spacefootball:PersistentLevel.BP_MyPlayerState_C_1: BeginPlay: Unique net id:
[2022.10.25-22.03.37:131][930]LogPlayerController: Error: BP_MyPlayerController_C /Game/Maps/spacefootball.spacefootball:PersistentLevel.BP_MyPlayerController_C_1: player controller not local player
[2022.10.25-22.03.37:131][930]LogOnlineSession: Warning: OSS: No game present to join for session (GameSession)
[2022.10.25-22.03.37:150][930]LogNet: Join succeeded: DESKTOP-4092S33-F23D
[2022.10.25-22.03.37:151][930]LogNet: Error: BP_MyPlayerController_C /Game/Maps/spacefootball.spacefootball:PersistentLevel.BP_MyPlayerController_C_1: UMyLocalPlayer* Player null
The errors regarding “PlayerController not local player” and “UMyLocalPlayer null” are custom errors that I put into the code. I don’t know whether or not I can expect the PlayerController instances to be local players.
Client log output:
[2022.10.25-22.03.39:794][895]LogUObjectGlobals: Warning: Gamethread hitch waiting for resource cleanup on a UObject (SplineMeshComponent /Game/Maps/spacefootball.spacefootball:PersistentLevel.BP_CharacterInSpace_C_1.SplineMesh.SplineMesh39) overwrite took 0.01ms. Fix the higher level code so that this does not happen.
[2022.10.25-22.03.39:733][895]PIE: Warning: Mobility of /Game/Maps/spacefootball.spacefootball:PersistentLevel.BP_CharacterInSpace_C_1 : Root has to be 'Movable' if you'd like to move.
[2022.10.25-22.03.39:737][895]LogOnlineSession: Warning: OSS: No game present to join for session (GameSession)
...
[2022.10.25-22.03.39:795][895]LogOnlineSession: Warning: OSS: No game present to join for session (GameSession)
EDIT:
Also somewhere in the logs shows up this line:
ReplicationDriverClass null! Not using ReplicationDriver.
AND
After a couple of minutes the host window freezes.