PackageTools.UnloadPackagesUnloadsPrimaryAssets

PackageTools.UnloadPackagesUnloadsPrimaryAssets

#Overview

name: PackageTools.UnloadPackagesUnloadsPrimaryAssets

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

It is referenced in 3 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of PackageTools.UnloadPackagesUnloadsPrimaryAssets is to control whether primary assets should be unloaded during the package unloading process in Unreal Engine.

This setting variable is primarily used by the UnrealEd module, specifically within the PackageTools system. It affects the package unloading functionality, which is a crucial part of the asset management and memory optimization in Unreal Engine.

The value of this variable is set through a console variable (CVar) system. It is initialized as a static boolean variable with a default value of true and then exposed as a console variable using FAutoConsoleVariableRef.

The associated variable bUnloadPackagesUnloadsPrimaryAssets directly interacts with PackageTools.UnloadPackagesUnloadsPrimaryAssets. They share the same value and purpose.

Developers must be aware that this variable affects the behavior of the UnloadPackages function in the UPackageTools class. When set to true, it causes the function to also unload primary assets associated with the packages being unloaded.

Best practices when using this variable include:

  1. Be cautious when changing its value, as it can affect memory management and asset loading behavior.
  2. Consider the implications on performance and asset availability when deciding whether to unload primary assets along with packages.
  3. Use it in conjunction with other asset management tools and practices to optimize memory usage and loading times.

Regarding the associated variable bUnloadPackagesUnloadsPrimaryAssets:

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Private/PackageTools.cpp:73

Scope (from outer to inner):

file
namespace    PackageTools_Private

Source code excerpt:

{
	static bool bUnloadPackagesUnloadsPrimaryAssets = true;
	FAutoConsoleVariableRef CVarUnloadPackagesUnloadsPrimaryAssets(TEXT("PackageTools.UnloadPackagesUnloadsPrimaryAssets"), bUnloadPackagesUnloadsPrimaryAssets, TEXT("During unload packages, also unload primary assets"), ECVF_Default);
}

/** State passed to RestoreStandaloneOnReachableObjects. */
TSet<UPackage*>* UPackageTools::PackagesBeingUnloaded = nullptr;
TSet<UObject*> UPackageTools::ObjectsThatHadFlagsCleared;
FDelegateHandle UPackageTools::ReachabilityCallbackHandle;

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Private/PackageTools.cpp:72

Scope (from outer to inner):

file
namespace    PackageTools_Private

Source code excerpt:

namespace PackageTools_Private
{
	static bool bUnloadPackagesUnloadsPrimaryAssets = true;
	FAutoConsoleVariableRef CVarUnloadPackagesUnloadsPrimaryAssets(TEXT("PackageTools.UnloadPackagesUnloadsPrimaryAssets"), bUnloadPackagesUnloadsPrimaryAssets, TEXT("During unload packages, also unload primary assets"), ECVF_Default);
}

/** State passed to RestoreStandaloneOnReachableObjects. */
TSet<UPackage*>* UPackageTools::PackagesBeingUnloaded = nullptr;
TSet<UObject*> UPackageTools::ObjectsThatHadFlagsCleared;
FDelegateHandle UPackageTools::ReachabilityCallbackHandle;

#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Private/PackageTools.cpp:495

Scope (from outer to inner):

file
function     bool UPackageTools::UnloadPackages

Source code excerpt:

				{
					// Asset manager can hold hard references to this object and prevent GC
					if (PackageTools_Private::bUnloadPackagesUnloadsPrimaryAssets)
					{
						const FPrimaryAssetId PrimaryAssetId = UAssetManager::Get().GetPrimaryAssetIdForObject(Obj);
						if (PrimaryAssetId.IsValid())
						{
							UAssetManager::Get().UnloadPrimaryAsset(PrimaryAssetId);
						}