GameSession (AInfo) BeginPlay not called

I see that classes derived from AInfo (like GameSession) should be used for Actors that don’t require physical representation in the game world. Now this is all fine and well however I’m seeing the following behaviour regarding the startup routine for these classes:

  • Constructor (called as usual)
  • OnConstruction (never called)
  • PostInitializeComponents (never called)
  • BeginPlay (never called)

Now I can understand why PostInitializeComponents is never executed, but I’m not sure about the rationale for disabling OnConstruction and BeginPlay for these classes. Does anyone have an explanation for this or is it a bug maybe?

The reason I’m asking is because I’m busy writing some serialisation code that is dependent on the order in which these functions are called for the core game framework classes (GameInstance, GameMode, GameSession, GameState, CameraManager, Character, Controller, HUD and PlayerState).

Hey staticvoidlol,

Could you post an the code that you’re using for your Info class where you’re not seeing BeginPlay be called so that I can take a closer look?

Hi Sean,

Thanks very much for the swift response.

Steps to reproduce:

  1. Create new basic C++ project (TestProject)
  2. Create new C++ class ‘MyGameSession’ derived from GameSession
  3. Add overrides for Constructor, OnConstruction, PostInitializeComponents and BeginPlay in ‘MyGameSession’ to log out when they are called (e.g. “UE_LOG(LogTemp, Warning, TEXT(“MyGameSession: PostInitializeComponents”));”)
  4. Create Blueprint ‘TestProjectGameModeBP’ derived from TestProjectGameMode.
  5. Open ‘TestProjectGameModeBP’ and set ‘GameSessionClass’ to ‘MyGameSession’
  6. Edit → Project Settings → Maps & Modes → Default Game Mode and set to ‘TestProjectGameModeBP’
  7. Run standalone game from VS and check that these functions are never called (nothing in log). You can verify this by using breakpoints as well.

Please let me know if anything is unclear.

Cheers!

I have reproduced the issue and entered a bug report, which you can track using the link below:

Thanks for your report.

Have a great day

When can we expect a fix for this? This is pretty big for me, and just wasted a couple days trying to figure this out. To clarify, when I try to override RegisterServer it also doesn’t work!

Currently, there is no timeline for when a fix will be released, as the developers are still investigating the issue.

Thanks very much Sean.

Seems like it got backlogged. That really sucks, this is super important to my project to register a dedicated server. I want to look at the issue myself, can you point me in the right direction? Thanks!

One of our developers began investigation the issue and discovered that the functions were in fact being called, and it was just the logging that wasn’t working, which is likely what prompted the backlogging. I’d recommend taking a look to see if any functionality that you place in those functions is still working, as it’s possible that the logging is just not showing up but no functionality is broken.

Let me know what you find.

So I put in functionality to write to a log file. It is using my GameSession class, as the constructor gets called and writes to the log file fine. But, it is not calling RegisterServer, BeginPlay, nothing, as far as I can tell. I’m assuming when you say logging you only mean the UE_LOG functionality correct?

Yeah that’s the functionality that I’m referring to.

Just to be clear, I did not use UE_LOG functionality. I wrote a custom function to log to a file, and that still did not work.

	FString SaveDirectory = FString("C:/Users/Null/Documents/Unreal Projects/Infantry");
	FString FileName = FString("Log.txt");
	FString TextToSave = FString("");


	IPlatformFile& PlatformFile = FPlatformFileManager::Get().GetPlatformFile();
	FString AbsoluteFilePath = SaveDirectory + "/" + FileName;
	FFileHelper::LoadFileToString(TextToSave, *AbsoluteFilePath);
	TextToSave += "custom state constructor\r\n";
	FFileHelper::SaveStringToFile(TextToSave, *AbsoluteFilePath);

Thanks for the information, I’ll go ahead and update the ticket with that and see if that sparks a new discussion.

Has there been any update on this? I’m not convinced it’s a logging issue. Someone said they took a GameMode/GameSession from 4.12 and moved it to 4.13 and it started working properly. I’ve got steam working with listen sessions and everything, but dedicated server is still a no go.

As of right now the issue is marked as backlogged. Feel free to keep track of the issue using the public tracker link I provided above.

Have a great day!

I think I’m seeing the exact same behavior with 4.14.3. I’ve overridden AGameSession::RegisterServer but it doesn’t appear that it’s ever being called.

I’m very convinced this has absolutely nothing to do with logging, and everything to do with it actually not being called. I’ve since given up and am waiting for Epic to implement a solution. No matter what I do inside RegisterServer, it never gets called.

Hi Sean,

I can confirm this is a bug calling a child’s functions and not a problem with UE_LOG. I’m using a source build of 4.14.3. I haven’t yet tried 4.15.

In my GameSession class, the following should cause my dedicated server to crash yet it runs fine:

void AICGameSession::PostInitializeComponents()
{
	UE_LOG(LogTemp, Warning, TEXT("AICGameSession::PostInitializeComponents"));
	UWorld* World = NULL;

	if (World->WorldType == 1)
	{
		StartDedicatedServer();
	}
}

When I put the following in my GameSession constructor it crashes as expected:

AICGameSession::AICGameSession(const FObjectInitializer& ObjectInitializer)
	: Super(ObjectInitializer)
{
	UE_LOG(LogTemp, Warning, TEXT("Creating AICGameSession"));
	UWorld* World = NULL;
	if (World->WorldType == 1)
	{
		StartDedicatedServer();
	}
}

My log file includes:

[2017.02.18-23.32.20:571][  0]LogTemp:Warning: Creating AICGameSession
[2017.02.18-23.32.21:061][  0]LogWindows:Error: === Critical error: ===
[2017.02.18-23.32.21:062][  0]LogWindows:Error: 
[2017.02.18-23.32.21:063][  0]LogWindows:Error: Fatal error!
[2017.02.18-23.32.21:063][  0]LogWindows:Error: 
[2017.02.18-23.32.21:063][  0]LogWindows:Error: Unhandled Exception: EXCEPTION_ACCESS_VIOLATION reading address 0x00000878

I cut off the traceback due to space constraints.

This is a showstopper for us. Thanks.

Digging through UnrealSlackers on Discord turned up the fact that GameModeBase::GetGameSession always returns AGameSession and not what you have set for GameSession on your GameMode. In other words, you have to override GameModeBase::GetGameSession to return your GameSession class. Now it’s working again. I’m not sure if this is an actual bug or just a gap in documentation.

Trandles you hero - nice find. Thanks for sharing.