OnlineSession vs GameSession

DELGOODIE
Sat, 11 Jan 2025 23:00:08 +0000
C++

@FrostyJas o the unreal framework provides two classes: UOnlineSession and AGameSession. Both with seemingly similar functionality. The differences are:

UOnlineSession

Owned by Game Instance

Persists for lifetime of application

Exists on clients and servers

Very much so a shell of a class (only 6 virtual functions with ZERO default implementations)

AGameSession

Owned by GameModeBase

Only on server

Exists for lifetime of the gamemode / world

Tons of functionality with default implementations and ties to AGameMode

So I’m torn because on the one hand, I need to implement my session logic in a way that is persistent across Worlds, especially for continuous playlist sessions or map vote switches, leaning me toward OnlineSession. I don’t want to do some hacky solution with the GameSession where I make a temp copy of the important state data in order to transition levels.
On the other hand, GameSession has a ton of existing functionality and is already designed to hook deeply into the GameMode with player registering, match starting, stopping, etc.

Is there a right answer here?

edit: @FrostyJas thanks for responding, this was the origininal post but i didn’t know that i can carry the game session actor across seamless travels, so i think this is the correct option!

6 posts - 4 participants