MaximumLoopIterationCount

MaximumLoopIterationCount

#Overview

name: MaximumLoopIterationCount

The value of this variable can be defined or overridden in .ini config files. 1 .ini config file referencing this setting variable.

It is referenced in 3 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of MaximumLoopIterationCount is to set a threshold for the maximum number of iterations allowed in Blueprint script loops. It serves as a safety measure to prevent infinite loops or excessively long-running scripts in the Unreal Engine’s Blueprint system.

This setting variable is primarily used by the Unreal Engine’s Blueprint system, which is a core part of the engine’s scripting capabilities. Based on the callsites, it’s clear that the Editor subsystem and the main Engine module rely on this variable.

The value of this variable is set in the engine configuration, as indicated by the UPROPERTY macro with the ‘config’ specifier in the Engine.h file. It can also be modified through the editor, triggering the PostEditChangeProperty function in EditorEngine.cpp.

MaximumLoopIterationCount interacts with the Blueprint core system through the FBlueprintCoreDelegates::SetScriptMaximumLoopIterations function, which is called whenever the value is changed or when the engine is initialized.

Developers must be aware that this variable has a significant impact on Blueprint performance and safety. Setting it too low might cause legitimate scripts to fail, while setting it too high could allow poorly optimized or buggy scripts to consume excessive resources.

Best practices when using this variable include:

  1. Keeping the value within a reasonable range (the engine clamps it between 100 and 10,000,000).
  2. Monitoring Blueprint performance and adjusting the value if necessary.
  3. Encouraging developers to optimize their Blueprint scripts rather than relying on a high iteration count.
  4. Being cautious when modifying this value, as it affects all Blueprint scripts in the project.
  5. Considering the target platform’s capabilities when setting this value, especially for mobile or lower-end devices.

#Setting Variables

#References In INI files

Location: <Workspace>/Engine/Config/BaseEngine.ini:279, section: [/Script/Engine.Engine]

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Private/EditorEngine.cpp:2564

Scope (from outer to inner):

file
function     void UEditorEngine::PostEditChangeProperty

Source code excerpt:

	const FName PropertyName = PropertyChangedEvent.Property ? PropertyChangedEvent.Property->GetFName() : NAME_None;

	if (PropertyName == GET_MEMBER_NAME_CHECKED(UEngine, MaximumLoopIterationCount))
	{
		// Clamp to a reasonable range and feed the new value to the script core
		MaximumLoopIterationCount = FMath::Clamp( MaximumLoopIterationCount, 100, 10000000 );
		FBlueprintCoreDelegates::SetScriptMaximumLoopIterations( MaximumLoopIterationCount );
	}
	else if (PropertyName == GET_MEMBER_NAME_CHECKED(UEngine, bCanBlueprintsTickByDefault))
	{
		FScopedSlowTask SlowTask(100, LOCTEXT("DirtyingBlueprintsDueToTickChange", "InvalidatingAllBlueprints"));

		// Flag all Blueprints as out of date (this doesn't dirty the package as needs saving but will force a recompile during PIE)

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Classes/Engine/Engine.h:1446

Scope (from outer to inner):

file
class        class UEngine : public UObject , public FExec

Source code excerpt:

	/** Script maximum loop iteration count used as a threshold to warn users about script execution runaway */
	UPROPERTY(EditAnywhere, config, Category=Blueprints)
	int32 MaximumLoopIterationCount;

	// Controls whether Blueprint subclasses of actors or components can tick by default.
	//
	// Blueprints that derive from native C++ classes that have bCanEverTick=true will always be able to tick
	// Blueprints that derive from exactly AActor or UActorComponent will always be able to tick
	// Otherwise, they can tick as long as the parent doesn't have meta=(ChildCannotTick) and either bCanBlueprintsTickByDefault is true or the parent has meta=(ChildCanTick)

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/UnrealEngine.cpp:2078

Scope (from outer to inner):

file
function     void UEngine::Init

Source code excerpt:


	// Update Script Maximum loop iteration count
	FBlueprintCoreDelegates::SetScriptMaximumLoopIterations( GEngine->MaximumLoopIterationCount );

	SetNearClipPlaneGlobals(NearClipPlane);

	UTextRenderComponent::InitializeMIDCache();

	if (GIsEditor)