OnlineSubsystem, IOnlineSession::CreateServer - Spawning problem (or testing problem?)

Hi again. I have been working on making a multiplayer game. I first followed the Unreal Multiplayer example and my game worked fine. So I had a map named “dev_scene” and if I make two clients in the Game Preview they both spawn separately and using Server RPC I was able to replicate the crouching, running animation etc and movement was automatically replicated by CharacterController.
So far so good :smiley:

Then I found the excellent tutorials on Youtube (Unreal Engine C++ Steam Server: Part 1: "Project Setup" - YouTube), he has shown me how to add the OnlineSubsystem to the build.cs file. And my “defaultEngine.ini” now looks like this:



[/Script/EngineSettings.GameMapsSettings]
GameDefaultMap=/Game/Scenes/MainMenu.MainMenu
EditorStartupMap=/Game/Scenes/MainMenu.MainMenu
GlobalDefaultGameMode=/Game/Blueprints/BP_mMenu_GameModeBase.BP_mMenu_GameModeBase_C
GameInstanceClass=/Script/OnlineShooter.OnShooter_GameInstance

[/Script/HardwareTargeting.HardwareTargetingSettings]
TargetedHardwareClass=Desktop
AppliedTargetedHardwareClass=Desktop
DefaultGraphicsPerformance=Maximum
AppliedDefaultGraphicsPerformance=Maximum

[/Script/Engine.Engine]
+ActiveGameNameRedirects=(OldGameName="TP_Blank",NewGameName="/Script/OnlineShooter")
+ActiveGameNameRedirects=(OldGameName="/Script/TP_Blank",NewGameName="/Script/OnlineShooter")
+ActiveClassRedirects=(OldClassName="TP_BlankGameModeBase",NewClassName="OnlineShooterGameModeBase")

[/Script/Engine.GameEngine]
+NetDriverDefinitions=(DefName="GameNetDriver",DriverClassName="OnlineSubsystemSteam.SteamNetDriver",DriverClassNameFallback="OnlineSubsystemUtils.IpNetDriver")

[OnlineSubsystem]
DefaultPlatformService=NULL

[OnlineSubsystemSteam]
bEnabled=true
SteamDevAppId=480
GameServerQueryPort=27015

[/Script/OnlineSubsystemSteam.SteamNetDriver]
NetConnectionClassName="OnlineSubsystemSteam.SteamNetConnection"

The functions he uses seem to do what I need. And later in the tutorial series indeed he apparently uses Steam “Space Wars” to test online and in theory eventually launch a game on Steam.

But after I made the Main Menu like in his tutorial, I try Create Server and it loads in all seems ok. But then I try to Join with another and then I suffer varying problems. The problems vary depending if I choose “Play Standalone; Listen Server or Client” in the Preview button.

For example if I click Play as Listen Server, and open 2 previews. I click Start Server in window A and window B has the player spawn in there. And if I move the mouse in Window B suddenly in jumps back to Window A.

Again, the logic worked fine in the main gameplay map. But the Menu with the start server button is not testing well. I’m unsure if the problem is caused by the way I test it.

The full project is on my Github:

If it would help I can post all the code here as well as images of the blueprints. Let me know if you want me to do that. Many thanks for any help.

Also note: I have port-forwarded both protocol for 7777 and 27015

Here are a few things:

  • When testing online features through the editor, always use “Play Standalone”, and in the settings, disable “run under one process”.
  • When testing online features, you’ll most likely want to enable logging. Use the -LOG launch param.
  • Session name is NOT the name of the session. It’s the session’s “type”. You should always use either GameSessionName or PartySessionName.
  • You should set the NumPublicConnections instead of the private connections. I still haven’t figured out what the intended use case of the private connections are :confused:
  • I’m not sure why you are calling the CreateSession function with player index 1? The first (local) player’s index is 0.
1 Like

Thank you this is much to get on with. Thanks for noticing the 1 in the player index, that was just something stupid I tried when testing and must have forgotten to change it back (or maybe didnt push to github yet).

As for the rest I will give it a try with all the settings you mention.

By the way, after looking at my code, do you think most of it is correct and should function properly so far (except of course the player index = 1 thing) or does it need to be completely deleted and re-written?

(Thanks again for the help so far)

EDIT: I think those settings have done the trick. I haven’t been able to figure out what you mean by adding -LOG yet but the game seems to run properly now. Although of course I haven’t quite implemented the “Join Server” part yet to properly test this.

The settings you mentioned (as well as the PUBLIC connections mistake you also found) has fixed the issue for now I think. I’m getting stuck in later again to try add more functions.

You can give additional launch params for the game, same as when you give launch params to an exe. The log launch param will open an additional window where you’ll be able to see a lot more information about what’s going on under the hood.

Got it now thanks yes. But sadly I am still encountering lots of bugs and cannot successfully Join a server. Creating one seems to work as far as I can tell. I will have to try to do a lot of debugging and also a lot more reading/watching documentation and tutorials on it. Sadly there isn’t too much help online for C++ networking compared to blueprint. The Unreal documentation for Networked Gaming kinda reads like an unfinished tutorial tbh (sorry to diss Unreal). I struggle to find anything there about setting up direct-ip network or any other type of networked solution.

I will keep trying but I am a looong way off getting a working prototype just yet :frowning:

(Nb. I’m trying to keep my Github project updated so if anyone at any time manages to take a look and see some bugs that would be grand!)

If you use the Steam OnlineSubsystem then you need two different accounts on two different PC’s since you can only login to Steam in one Instance per PC.

Port forwarding is not necessary if you are using Steam since it will help with the NAT hole punching, but if you are simply directly connecting to an IP then the Host / Server needs proper Port Forwarding setup.

If you want to use Steam then

[OnlineSubsystem]
DefaultPlatformService=NULL

is wrong. It should be

[OnlineSubsystem]
DefaultPlatformService=Steam

Thank you for this information. I had tried NULL before Steam. So if I use ‘NULL’ do I still need two different PC’s to test it?