How can I trigger GameSession::RegisterServer in dedicated server in PIE mode?

I am a new user of Unreal, I am struggling to make below logic work in Unreal Editor.

What I want to do is to start a dedicated server and a client in the Editor. Instead of the client connects to the server directly, I want both the client and server to connect to a Matchmaker. And the matchmaker forms a match and send the Arena server details back to client. Then the client connects to the server. We have our own GameSession implementation to do the above logic. It works in below scenario:

From the “Play” drop down menu:

  • Enable “Run Dedicated Server”
  • Disable “Auto Connect To Server” in the “Advanced Settings"
  • Start the game using “Standalone Game”

But the logic does not work when I start the game using “Selected Viewport” from the “Play” drop down menu. After some debugging, I find that it relates to below logic. For some reason the “GetNetMode()” returns “NM_Standalone” and “GameSession->RegisterServer()” is not called.

void AGameModeBase::InitGame(const FString& MapName, const FString& Options, FString& ErrorMessage)
{
	...
	FGameModeEvents::GameModeInitializedEvent.Broadcast(this);
	if (GetNetMode() != NM_Standalone)
	{
		// Attempt to login, returning true means an async login is in flight
		if (!UOnlineEngineInterface::Get()->DoesSessionExist(World, GameSession->SessionName) && 
			!GameSession->ProcessAutoLogin())
		{
			GameSession->RegisterServer();
		}
	}
}

Any help is appreciated.

Regards,

I’m seeing the same in 4.21. Auto connect doesn’t seem to factor into it for us.

Looks like the world doesn’t have a net driver set on it yet at this point.

If you mean custom online subsystem it won’t be that easy of a task. Source look through that forum post for reference I myself referenced it including this page. Also look through these UE wiki pages since it does talk about Online Subsystem and my guess according to the user post on the forum you should be able to create scale down version of your own Online Subsystem.

I recommend getting into STEAM’s Online Subsystem and read this documentation

Creating your own Online SubSystem... - C++ Programming - Unreal Engine ForumsUse online subsystem for STEAM

At least for me, we’re just using the built-in OnlineSubsystemNull.

I had this same issue long ago, unfortunately (at least as of 4.21 which I am still using) PIE handles the connection between dedicated server and Client automatically. To test your dedicated server you need to perform a Server Build which requires a source built engine and launch the server. Then, technically to connect to it, you have to either package the game or build the client (both through through the editor) and launch that. You can still attach VS debugger to either of these processes if you need to debug code, the only issues I’ve had are problems that spring up on immediate launch, those are the best (worst) to figure out.

But with the dedicated server built you the Register Server Function is automatically called.

Build guide: A new, community-hosted Unreal Engine Wiki - Announcements - Unreal Engine Forums

@JeDeergab has other good links, and thanks for the “create your own online subsystem” been thinking of writing one for a while for testing purposes