QUIT_EDITOR

QUIT_EDITOR

#Overview

name: QUIT_EDITOR

This variable is created as a Console Variable (cvar).

It is referenced in 6 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of QUIT_EDITOR is to initiate the process of closing the Unreal Engine editor. This command is used to safely shut down the editor, ensuring that all necessary cleanup and saving operations are performed before the application exits.

QUIT_EDITOR is primarily used by the Unreal Engine’s editor subsystem, specifically within the MainFrame module and UnrealEd module. It’s also utilized by the EditorScriptingUtilities plugin and the Engine’s core runtime.

The value of this variable is not set directly; instead, it’s used as a command string that is passed to the engine’s command handling system. It’s typically added to the GEngine’s DeferredCommands array, which allows the engine to process the command at an appropriate time.

Other variables that interact with QUIT_EDITOR include:

Developers should be aware that:

  1. QUIT_EDITOR should be used instead of directly calling editor shutdown functions, as it ensures a safe and orderly shutdown process.
  2. The command is deferred, meaning it won’t execute immediately but will be processed at the next safe opportunity.
  3. This command is specific to the editor environment and should not be used in packaged games.

Best practices when using this variable include:

  1. Use QUIT_EDITOR instead of trying to manually close the editor through other means.
  2. Ensure all necessary data is saved before calling QUIT_EDITOR.
  3. Be cautious when using this command in scripts or automated processes, as it will terminate the editor session.
  4. In most cases, add the command to GEngine->DeferredCommands rather than executing it directly, to allow for proper shutdown sequencing.
  5. Only use this command when you’re certain that closing the editor is the desired action, as it will terminate the entire editing session.

#References in C++ code

#Callsites

This variable is referenced in the following C++ source code:

#Loc: <Workspace>/Engine/Plugins/Editor/EditorScriptingUtilities/Source/EditorScriptingUtilities/Private/EditorPythonExecuter.cpp:193

Scope (from outer to inner):

file
namespace    InternalEditorPythonRunner
class        class FExecuterTickable : FTickableEditorObject
function     void CloseEditor

Source code excerpt:

			if (GEngine)
			{
				GEngine->HandleDeferCommand(TEXT("QUIT_EDITOR"), *GLog); // Defer close the editor
			}
		}

		FString FileName;
		bool bIsRunning = false;
	};

#Loc: <Workspace>/Engine/Source/Editor/MainFrame/Private/Frame/MainFrameHandler.cpp:186

Scope (from outer to inner):

file
function     void FMainFrameHandler::ShutDownEditor

Source code excerpt:

	//       (such as MainFrame) to become unloaded out from underneath the code pointer.  We'll shut down
	//       as soon as it's safe to do so.
	// Note this is the only place in slate that should be calling QUIT_EDITOR
	GEngine->DeferredCommands.Add(TEXT("QUIT_EDITOR"));
}

void FMainFrameHandler::EnableTabClosedDelegate()
{
	if (MainTabPtr.IsValid())
	{

#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Private/EditorCommandLineUtils.cpp:446

Scope (from outer to inner):

file
function     static void EditorCommandLineUtilsImpl::ForceCloseEditor

Source code excerpt:

	// We used to call IMainFrameModule::RequestCloseEditor, but that runs a lot of logic that should only be
	// run for the real project editor (notably UThumbnailManager::CaptureProjectThumbnail was causing a crash on shutdown
	// but INI serialization was running when it should not have as well). Instead, we just raise the QUIT_EDITOR command:
	GEngine->DeferredCommands.Add(TEXT("QUIT_EDITOR"));
}

//------------------------------------------------------------------------------
static void EditorCommandLineUtilsImpl::RunAssetDiffCommand(TSharedPtr<SWindow> MainEditorWindow, bool bIsRunningStartupDialog, FString CommandArgs)
{
	// if the editor is running the project browser (or another like dialog on startup), 

#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Private/EditorServer.cpp:5704

Scope (from outer to inner):

file
function     bool UEditorEngine::Exec_Editor

Source code excerpt:

	}
	//----------------------------------------------------------------------------------
	// QUIT_EDITOR - Closes the wx main editor frame.  We need to do this in slate but it is routed differently.
	// Don't call quit_editor directly with slate
	//
	else if( FParse::Command(&Str,TEXT("QUIT_EDITOR")) )
	{
		CloseEditor();
		return true;
	}
	else if( FParse::Command(&Str,TEXT("CLOSE_SLATE_MAINFRAME")) )
	{

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/EngineService.cpp:188

Scope (from outer to inner):

file
function     void FEngineService::HandleTerminateMessage

Source code excerpt:

			if (GEngine->IsEditor())
			{
				GEngine->Exec( nullptr, TEXT("QUIT_EDITOR"), *GLog);
			}
			else
			{
				GEngine->Exec( nullptr, TEXT("QUIT"), *GLog);
			}
		}

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/KismetSystemLibrary.cpp:597

Scope (from outer to inner):

file
function     void UKismetSystemLibrary::QuitEditor

Source code excerpt:

void UKismetSystemLibrary::QuitEditor()
{
	GEngine->Exec(nullptr, TEXT("QUIT_EDITOR"), *GLog);
}
#endif	// WITH_EDITOR

bool UKismetSystemLibrary::K2_IsValidTimerHandle(FTimerHandle TimerHandle)
{
	return TimerHandle.IsValid();