AutoSaveIndex

AutoSaveIndex

#Overview

name: AutoSaveIndex

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 7 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of AutoSaveIndex is to manage the rotation of auto-save files in Unreal Engine 5’s editor. It is used to create unique filenames for auto-saved content, ensuring that multiple versions of auto-saved files are maintained without overwriting each other.

This setting variable is primarily used in the Unreal Editor subsystem, specifically within the file management and auto-save functionalities. The main modules that rely on this variable are UnrealEd and the PackageAutoSaver.

The value of AutoSaveIndex is set and incremented in the FPackageAutoSaver class, particularly in the AttemptAutoSave function. It is initialized to 0 in the FPackageAutoSaver constructor and incremented cyclically based on the AutoSaveMaxBackups setting.

AutoSaveIndex interacts with other variables such as AutoSaveMaxBackups, which determines the maximum number of auto-save files to keep before overwriting the oldest ones.

Developers must be aware that:

  1. AutoSaveIndex is used to create unique filenames for auto-saved content.
  2. It cycles from 0 to (AutoSaveMaxBackups - 1), wrapping around to 0 after reaching the maximum.
  3. Changing this value manually could lead to unexpected behavior in the auto-save system.

Best practices when using this variable include:

  1. Avoid manually modifying AutoSaveIndex, as it is managed automatically by the PackageAutoSaver.
  2. When implementing custom auto-save functionality, consider using a similar approach to rotate through multiple backup files.
  3. Be aware of the AutoSaveMaxBackups setting, as it directly affects how AutoSaveIndex behaves.
  4. When retrieving auto-saved files, use the GetAutoSaveFilename function, which takes AutoSaveIndex as a parameter, to ensure consistency with the auto-save system.

#Setting Variables

#References In INI files

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

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Private/FileHelpers.cpp:1051

Scope (from outer to inner):

file
function     FString FEditorFileUtils::GetAutoSaveFilename

Source code excerpt:

}

FString FEditorFileUtils::GetAutoSaveFilename(UPackage* const Package, const FString& AbsoluteAutosaveDir, const int32 AutoSaveIndex, const FString& PackageExt)
{
	// Come up with a meaningful name for the auto-save file
	const FString PackagePathName = Package->GetPathName();

	FString AutoSavePath;
	FString PackageRoot;

#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Private/FileHelpers.cpp:1075

Scope (from outer to inner):

file
function     FString FEditorFileUtils::GetAutoSaveFilename

Source code excerpt:


	// Create an auto-save filename
	const FString Filename = AutoSavePath / *FString::Printf(TEXT("%s_Auto%i%s"), *PackageName, AutoSaveIndex, *PackageExt);
	return Filename;
}

/** Renames a single level, preserving the common suffix */
bool RenameStreamingLevel( FString& LevelToRename, const FString& OldBaseLevelName, const FString& NewBaseLevelName )
{

#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Private/PackageAutoSaver.cpp:97

Scope (from outer to inner):

file
function     FPackageAutoSaver::FPackageAutoSaver

Source code excerpt:


FPackageAutoSaver::FPackageAutoSaver()
	: AutoSaveIndex(0)
	, AutoSaveCount(0.0f)
	, bIsAutoSaving(false)
	, bDelayingDueToFailedSave(false)
	, bAutoDeclineRecovery(FParse::Param(FCommandLine::Get(), TEXT("AutoDeclinePackageRecovery")))
{
	// Register for the package dirty state updated callback to catch packages that have been cleaned without being saved

#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Private/PackageAutoSaver.cpp:245

Scope (from outer to inner):

file
function     void FPackageAutoSaver::AttemptAutoSave

Source code excerpt:

			const int32 AutoSaveMaxBackups = LoadingSavingSettings->AutoSaveMaxBackups > 0 ? LoadingSavingSettings->AutoSaveMaxBackups : 10;
			// Auto-save maps and/or content packages based on user settings.
			const int32 NewAutoSaveIndex = (AutoSaveIndex + 1) % AutoSaveMaxBackups;

			EAutosaveContentPackagesResult::Type MapsSaveResults = EAutosaveContentPackagesResult::NothingToDo;
			EAutosaveContentPackagesResult::Type AssetsSaveResults = EAutosaveContentPackagesResult::NothingToDo;

			if (LoadingSavingSettings->AutoSaveMethod == EAutoSaveMethod::BackupAndRestore)
			{

#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Private/PackageAutoSaver.cpp:376

Scope (from outer to inner):

file
function     void FPackageAutoSaver::AttemptAutoSave

Source code excerpt:

			{
				// If a level was actually saved, update the auto-save index
				AutoSaveIndex = NewAutoSaveIndex;

				// Update the restore information
				UpdateRestoreFile(PackageAutoSaverJson::IsRestoreEnabled());
			}

			ResetAutoSaveTimer();

#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Private/PackageAutoSaver.h:116

Scope (from outer to inner):

file
class        class FPackageAutoSaver : public IPackageAutoSaver

Source code excerpt:


	/** The current auto-save number, appended to the auto-save map name, wraps after 10 */
	int32 AutoSaveIndex;

	/** The number of 10-sec intervals that have passed since last auto-save. */
	float AutoSaveCount;

	/** If we are currently auto-saving */
	bool bIsAutoSaving;

#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Public/FileHelpers.h:322

Scope (from outer to inner):

file
class        class FEditorFileUtils

Source code excerpt:

	 * @param	PackageExt					Extension to use for the given package. Note: This must include the dot.
	 */
	static FString GetAutoSaveFilename(UPackage* const Package, const FString& AbsoluteAutosaveDir, const int32 AutoSaveIndex, const FString& PackageExt);

	/**
	 * Saves all levels to the specified directory.
	 *
	 * @param	AbsoluteAutosaveDir			Autosave directory.
	 * @param	AutosaveIndex				Integer prepended to autosave filenames..