Issues trying to include online session types in GameSession.cpp

I’ve been trying to change the following function in GameSession.cpp

void AGameSession::RegisterServer()
{
}

to

void AGameSession::RegisterServer()
{
	UWorld* World = GetWorld();
	IOnlineSessionPtr SessionInt = Online::GetSessionInterface(World);

	FOnlineSessionSettings Settings;
	Settings.NumPublicConnections = 42;
	Settings.bShouldAdvertise = true;
	Settings.bAllowJoinInProgress = true;
	Settings.bIsLANMatch = false;
	Settings.bUsesPresence = true;
	Settings.bAllowJoinViaPresence = true;

	SessionInt->CreateSession(0, GameSessionName, Settings);
	return;
}

However, I get 28 errors related to undeclared identifiers, such as:

'IOnlineSessionPtr': undeclared identifier
'SessionInt': undeclared identifier
'FOnlineSessionSettings': undeclared identifier
...

I assume this is because I need to #include some headers to access online types and functions. However, #including “Online.h” and “OnlineSubsystemUtils.h” came up with errors claiming that they could not be found, and #including their absolute filepaths ended up giving 99 errors.

Any advice?

PS. both the header files are in the /Plugins folder and not the /Runtime folder. Is that important?

Yes, OnlineSubsystem is in there:

PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "AdvancedSessions", "VRExpansionPlugin", "OnlineSubsystem", "OnlineSubsystemSteam", "OnlineSubsystemUtils" });
PrivateDependencyModuleNames.AddRange(new string[] {  });
DynamicallyLoadedModuleNames.Add("OnlineSubsystemNull");

The MYPROJECT.h file has

#include "UnrealNetwork.h"
#include "Online.h"

Is that the right place to put them?

Error might be because I am trying to access a plugin’s file from inside the engine source code. I assume that is the issue.

Have you added “OnlineSubsystem” to your MYPROJECT.Build.cs file?

		PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "OnlineSubsystem" });

How about?:

#include "UnrealNetwork.h"

(alongside Online.h)

For 4.15, that is probably fine as long as you are including your MYPROJECT.h file in your GameSession.cpp file.

This is the only reference I have used for game sessions and I haven’t used in months:

https://wiki.unrealengine.com/How_To_Use_Sessions_In_C%2B%2B

I do know that when I used it, it was fine. Probably somewhere around 4.13 - 4.14.