core.EnsureAlwaysEnabled

core.EnsureAlwaysEnabled

#Overview

name: core.EnsureAlwaysEnabled

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

It is referenced in 4 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of core.EnsureAlwaysEnabled is to control the behavior of the ensureAlways macro in Unreal Engine’s assertion system. This setting variable is part of the core debugging and error-handling functionality in Unreal Engine 5.

This setting variable is primarily used in the Core module of Unreal Engine, specifically in the assertion macros system. It’s referenced in the AssertionMacros.cpp file, which is a crucial part of Unreal Engine’s debugging infrastructure.

The value of this variable is set through an FAutoConsoleVariableRef named CVarEnsureAlwaysEnabled. This means it can be modified at runtime through the console or configuration files.

The core.EnsureAlwaysEnabled variable interacts closely with its associated variable GEnsureAlwaysEnabled. They share the same value, with GEnsureAlwaysEnabled being the actual boolean variable used in the code logic.

Developers must be aware that this variable affects the behavior of the ensureAlways macro. When set to false, it turns ensureAlways into a regular ensure, potentially changing the error-handling behavior of the engine.

Best practices when using this variable include:

  1. Keeping it enabled (true) during development to catch all potential issues.
  2. Being cautious when disabling it, as it may hide critical errors.
  3. Understanding that changing this value can significantly impact the engine’s error reporting and handling.

Regarding the associated variable GEnsureAlwaysEnabled:

The purpose of GEnsureAlwaysEnabled is to serve as the actual boolean flag that controls the behavior of ensureAlways checks in the code.

This variable is used directly in the Core module’s assertion system, specifically in the ExecCheckImplInternal and EnsureFailed functions.

The value of GEnsureAlwaysEnabled is set at initialization to true and can be modified through the core.EnsureAlwaysEnabled console variable.

GEnsureAlwaysEnabled interacts closely with the assertion system and affects the behavior of ensureAlways checks throughout the engine.

Developers should be aware that modifying GEnsureAlwaysEnabled directly is not recommended. Instead, they should use the core.EnsureAlwaysEnabled console variable to change its value.

Best practices for GEnsureAlwaysEnabled include:

  1. Treating it as read-only in most scenarios.
  2. Understanding its impact on the engine’s error checking system.
  3. Using it in conjunction with other debugging tools and practices for comprehensive error detection and handling.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Core/Private/Misc/AssertionMacros.cpp:114

Scope: file

Source code excerpt:

bool GEnsureAlwaysEnabled = true;
FAutoConsoleVariableRef CVarEnsureAlwaysEnabled(
	TEXT("core.EnsureAlwaysEnabled"),
	GEnsureAlwaysEnabled,
	TEXT("Set to false to turn ensureAlways into regular ensure"),
	ECVF_Default);


CORE_API void (*GPrintScriptCallStackFn)() = nullptr;

#Associated Variable and Callsites

This variable is associated with another variable named GEnsureAlwaysEnabled. They share the same value. See the following C++ source code.

#Loc: <Workspace>/Engine/Source/Runtime/Core/Private/Misc/AssertionMacros.cpp:112

Scope: file

Source code excerpt:

	ECVF_Default);

bool GEnsureAlwaysEnabled = true;
FAutoConsoleVariableRef CVarEnsureAlwaysEnabled(
	TEXT("core.EnsureAlwaysEnabled"),
	GEnsureAlwaysEnabled,
	TEXT("Set to false to turn ensureAlways into regular ensure"),
	ECVF_Default);


CORE_API void (*GPrintScriptCallStackFn)() = nullptr;

#Loc: <Workspace>/Engine/Source/Runtime/Core/Private/Misc/AssertionMacros.cpp:776

Scope (from outer to inner):

file
function     bool UE_DEBUG_SECTION UE::Assert::Private::ExecCheckImplInternal

Source code excerpt:

bool UE_DEBUG_SECTION UE::Assert::Private::ExecCheckImplInternal(std::atomic<bool>& bExecuted, bool bAlways, const ANSICHAR* File, int32 Line, const ANSICHAR* Expr)
{
	if (((bAlways && GEnsureAlwaysEnabled) || !bExecuted.load(std::memory_order_relaxed)) && FPlatformMisc::IsEnsureAllowed())
	{
		if (bExecuted.exchange(true, std::memory_order_release) && !bAlways)
		{
			return false;
		}

#Loc: <Workspace>/Engine/Source/Runtime/Core/Private/Misc/AssertionMacros.cpp:792

Scope (from outer to inner):

file
function     bool UE_DEBUG_SECTION VARARGS UE::Assert::Private::EnsureFailed

Source code excerpt:

bool UE_DEBUG_SECTION VARARGS UE::Assert::Private::EnsureFailed(std::atomic<bool>& bExecuted, const FStaticEnsureRecord* Ensure, ...)
{
	if (bExecuted.exchange(true, std::memory_order_release) && !(Ensure->bAlways && GEnsureAlwaysEnabled))
	{
		return false;
	}

	va_list Args;
	va_start(Args, Ensure);