Event on Close

I’m looking for an overridable function or event to listen for the window of the game being closed. I need to do some cleanup operations before the window can be allowed to close up.

I’ve tried Destroyed() and EndPlay() in the AGameMode class without any luck

1 Like

Hi Aaron,

I think the best way to do this. It is create custom game engine class and implement events you want.

You should add to DefaultEngine.ini

[/Script/Engine.Engine]
GameEngine=/Script/QAGame.MyCustomGameEngine

MyCustomGameEngine.h

#pragma once

#include "Engine/GameEngine.h"
#include "MyCustomGameEngine.generated.h"

UCLASS()
class UMyCustomGameEngine : public UGameEngine
{
	GENERATED_UCLASS_BODY()


	// When engine starts
	void Init(class IEngineLoop* InEngineLoop);
	// Close engine
	void PreExit();
};

MyCustomGameEngine.cpp

#include "QAGame.h"
#include "MyCustomGameEngine.h"

UMyCustomGameEngine::UMyCustomGameEngine(const FPostConstructInitializeProperties& PCIP)
: Super(PCIP)
{}

void UMyCustomGameEngine::Init(class IEngineLoop* InEngineLoop)
{
	Super::Init(InEngineLoop);
}

void UMyCustomGameEngine::PreExit()
{
	Super::PreExit();
}

Best regards,

Exactly what I was looking for

I’ve got syntax errors when trying to recompile my project :frowning: Can you help me?

There’s a GameInstance to handle this.

Init: UGameInstance::Init | Unreal Engine Documentation

Shutdown: UGameInstance::Shutdown | Unreal Engine Documentation