diff --git a/Source/Engine/Engine/Base/GameBase.cpp b/Source/Engine/Engine/Base/GameBase.cpp
index 5fb28a118..ea4201142 100644
--- a/Source/Engine/Engine/Base/GameBase.cpp
+++ b/Source/Engine/Engine/Base/GameBase.cpp
@@ -199,6 +199,7 @@ void GameBaseImpl::OnMainWindowClosed()
// Request engine exit
Globals::IsRequestingExit = true;
+ Engine::RequestingExit();
}
void GameBaseImpl::OnPostRender(GPUContext* context, RenderContext& renderContext)
diff --git a/Source/Engine/Engine/Engine.cpp b/Source/Engine/Engine/Engine.cpp
index af62e0b6e..b26cbd25a 100644
--- a/Source/Engine/Engine/Engine.cpp
+++ b/Source/Engine/Engine/Engine.cpp
@@ -70,6 +70,7 @@ Action Engine::LateFixedUpdate;
Action Engine::Draw;
Action Engine::Pause;
Action Engine::Unpause;
+Action Engine::RequestingExit;
Window* Engine::MainWindow = nullptr;
int32 Engine::Main(const Char* cmdLine)
@@ -259,10 +260,12 @@ void Engine::RequestExit(int32 exitCode)
{
Globals::IsRequestingExit = true;
Globals::ExitCode = exitCode;
+ RequestingExit();
}
#else
Globals::IsRequestingExit = true;
Globals::ExitCode = exitCode;
+ RequestingExit();
#endif
}
diff --git a/Source/Engine/Engine/Engine.h b/Source/Engine/Engine/Engine.h
index 15285a07e..85ffefda0 100644
--- a/Source/Engine/Engine/Engine.h
+++ b/Source/Engine/Engine/Engine.h
@@ -79,6 +79,11 @@ public:
///
static Action Unpause;
+ ///
+ /// Event called when the engine is requesting exit.
+ ///
+ API_EVENT() static Action RequestingExit;
+
public:
///
diff --git a/Source/Engine/Engine/Globals.h b/Source/Engine/Engine/Globals.h
index 79b4955a3..670eecd4c 100644
--- a/Source/Engine/Engine/Globals.h
+++ b/Source/Engine/Engine/Globals.h
@@ -2,6 +2,7 @@
#pragma once
+#include "Engine/Core/Delegate.h"
#include "Engine/Scripting/ScriptingType.h"
#include "Engine/Input/Enums.h"
@@ -59,9 +60,19 @@ DECLARE_SCRIPTING_TYPE_NO_SPAWN(Globals);
// True if fatal error occurred (engine is exiting)
static bool FatalErrorOccurred;
- // True if engine need to be closed
+ // True if engine needs to be closed
static bool IsRequestingExit;
+ ///
+ /// True if engine needs to be closed
+ ///
+ API_PROPERTY() FORCE_INLINE static bool GetIsRequestingExit() { return IsRequestingExit; }
+
+ ///
+ /// True if fatal error occurred (engine is exiting)
+ ///
+ API_PROPERTY() FORCE_INLINE static bool GetFatalErrorOccurred() { return FatalErrorOccurred; }
+
// Exit code
static int32 ExitCode;
diff --git a/Source/Engine/Platform/Base/PlatformBase.cpp b/Source/Engine/Platform/Base/PlatformBase.cpp
index 8a6baf4bc..6efa3c8b4 100644
--- a/Source/Engine/Platform/Base/PlatformBase.cpp
+++ b/Source/Engine/Platform/Base/PlatformBase.cpp
@@ -271,6 +271,7 @@ void PlatformBase::Fatal(const Char* msg, void* context)
Globals::FatalErrorOccurred = true;
Globals::IsRequestingExit = true;
Globals::ExitCode = -1;
+ Engine::RequestingExit();
// Collect crash info (platform-dependant implementation that might collect stack trace and/or create memory dump)
{