DirectoriesToAlwaysCook

DirectoriesToAlwaysCook

#Overview

name: DirectoriesToAlwaysCook

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

It is referenced in 7 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of DirectoriesToAlwaysCook is to specify additional directories containing assets that should always be included in the game’s cooked content, regardless of whether they are directly referenced by the project.

This setting variable is primarily used by Unreal Engine’s packaging and cooking systems. It is relied upon by the following modules and plugins:

  1. DatasmithRuntime plugin
  2. DeveloperToolSettings module
  3. UnrealEd module (CookCommandlet, GenerateDistillFileSetsCommandlet, and CookOnTheFlyServer)

The value of this variable is typically set in the project’s packaging settings, which can be accessed and modified through the Project Settings menu in the Unreal Editor. It is stored as a config property in the UProjectPackagingSettings class.

DirectoriesToAlwaysCook interacts with other packaging-related variables and systems, such as DirectoriesToNeverCook and the overall asset cooking process.

Developers should be aware of the following when using this variable:

  1. Paths should be specified either as full package paths (e.g., /Game/Folder, /Engine/Folder, /PluginName/Folder) or as relative paths from the /Game directory.
  2. The DatasmithRuntime plugin automatically adds its materials path to this list to ensure proper runtime functionality.
  3. Invalid paths will be logged as warnings and skipped during the cooking process.

Best practices for using this variable include:

  1. Use it sparingly to avoid unnecessarily increasing the size of your packaged game.
  2. Regularly review and update the list to ensure all necessary assets are included while removing any obsolete entries.
  3. Be mindful of the performance impact of including large directories, especially for mobile or web-based projects.
  4. Use in conjunction with DirectoriesToNeverCook to fine-tune your project’s packaging process.
  5. When adding paths programmatically, ensure they are properly formatted and valid to avoid issues during the cooking process.

#Setting Variables

#References In INI files

Location: <Workspace>/Engine/Plugins/Runtime/XR/XRVisualization/Config/BaseXRVisualization.ini:2, section: [/Script/UnrealEd.ProjectPackagingSettings]

Location: <Workspace>/Engine/Plugins/Runtime/XR/XRVisualization/Config/BaseXRVisualization.ini:3, section: [/Script/UnrealEd.ProjectPackagingSettings]

Location: <Workspace>/Engine/Plugins/Runtime/XR/XRVisualization/Config/BaseXRVisualization.ini:4, section: [/Script/UnrealEd.ProjectPackagingSettings]

Location: <Workspace>/Engine/Plugins/Runtime/XR/XRVisualization/Config/BaseXRVisualization.ini:5, section: [/Script/UnrealEd.ProjectPackagingSettings]

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Plugins/Experimental/Enterprise/DatasmithRuntime/Source/Private/DatasmithRuntimeModule.cpp:34

Scope (from outer to inner):

file
class        class FDatasmithRuntimeModule : public IDatasmithRuntimeModuleInterface
function     virtual void StartupModule

Source code excerpt:

			bool bAlreadyInPath = false;

			TArray<FDirectoryPath>& DirectoriesToCook = PackagingSettings->DirectoriesToAlwaysCook;
			for ( int32 Index = DirectoriesToCook.Num() - 1; Index >= 0; --Index )
			{
				if ( FPaths::IsSamePath( DirectoriesToCook[ Index ].Path, MaterialsPath ) )
				{
					bAlreadyInPath = true;
					break;

#Loc: <Workspace>/Engine/Plugins/Experimental/Enterprise/DatasmithRuntime/Source/Private/DatasmithRuntimeModule.cpp:49

Scope (from outer to inner):

file
class        class FDatasmithRuntimeModule : public IDatasmithRuntimeModuleInterface
function     virtual void StartupModule

Source code excerpt:

				MaterialsDirectory.Path = MaterialsPath;

				PackagingSettings->DirectoriesToAlwaysCook.Add( MaterialsDirectory );

				UE_LOG(LogDatasmithRuntime, Log, TEXT("Adding %s to the list of directories to always package otherwise we cannot create dynamic material instances at runtime"), MaterialsPath);
			}
		}
#endif // WITH_EDITOR

#Loc: <Workspace>/Engine/Source/Developer/DeveloperToolSettings/Classes/Settings/ProjectPackagingSettings.h:575

Scope (from outer to inner):

file
class        class UProjectPackagingSettings : public UObject

Source code excerpt:

	 */
	UPROPERTY(config, EditAnywhere, Category=Packaging, AdvancedDisplay, meta=(DisplayName="Additional Asset Directories to Cook", LongPackageName))
	TArray<FDirectoryPath> DirectoriesToAlwaysCook;

	/**
	 * Directories containing .uasset files that should never be cooked even if they are referenced by your project
	 * These paths are stored either as a full package path (e.g. /Game/Folder, /Engine/Folder, /PluginName/Folder) or as a relative package path from /Game
	 */
	UPROPERTY(config, EditAnywhere, Category = Packaging, AdvancedDisplay, meta = (DisplayName = "Directories to never cook", LongPackageName))

#Loc: <Workspace>/Engine/Source/Developer/DeveloperToolSettings/Private/ProjectPackagingSettings.cpp:54

Scope (from outer to inner):

file
function     void UProjectPackagingSettings::FixCookingPaths

Source code excerpt:

{
	// Fix AlwaysCook/NeverCook paths to use content root
	for (FDirectoryPath& PathToFix : DirectoriesToAlwaysCook)
	{
		if (!PathToFix.Path.IsEmpty() && !PathToFix.Path.StartsWith(TEXT("/"), ESearchCase::CaseSensitive))
		{
			PathToFix.Path = FString::Printf(TEXT("/Game/%s"), *PathToFix.Path);
		}
	}

#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Private/Commandlets/CookCommandlet.cpp:431

Scope (from outer to inner):

file
function     bool UCookCommandlet::CookByTheBook

Source code excerpt:

	if (!(CookOptions & ECookByTheBookOptions::NoGameAlwaysCookPackages))
	{
		for (const FDirectoryPath& DirToCook : PackagingSettings->DirectoriesToAlwaysCook)
		{
			FString LocalPath;
			if (FPackageName::TryConvertGameRelativePackagePathToLocalPath(DirToCook.Path, LocalPath))
			{
				CmdLineDirEntries.Add(LocalPath);
			}

#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Private/Commandlets/GenerateDistillFileSetsCommandlet.cpp:296

Scope (from outer to inner):

file
function     int32 UGenerateDistillFileSetsCommandlet::Main

Source code excerpt:


	// Add assets from additional directories to always cook
	for (const auto& DirToCook : PackagingSettings->DirectoriesToAlwaysCook)
	{
		FString DirectoryPath;
		if (!FPackageName::TryConvertGameRelativePackagePathToLocalPath(DirToCook.Path, DirectoryPath))
		{
			UE_LOG(LogGenerateDistillFileSetsCommandlet, Warning, TEXT("'ProjectSettings -> Project -> Packaging -> Directories to always cook' has invalid element '%s'"), *DirToCook.Path);
			continue;

#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Private/CookOnTheFlyServer.cpp:9030

Scope (from outer to inner):

file
function     void UCookOnTheFlyServer::CollectFilesToCook

Source code excerpt:

		// Also append any cookdirs from the project ini files; these dirs are relative to the game content directory or start with a / root
		{
			for (const FDirectoryPath& DirToCook : PackagingSettings->DirectoriesToAlwaysCook)
			{
				FString LocalPath;
				if (FPackageName::TryConvertGameRelativePackagePathToLocalPath(DirToCook.Path, LocalPath))
				{
					UE_LOG(LogCook, Verbose, TEXT("Loading directory to always cook %s"), *DirToCook.Path);
					FName LocalPathFName(*LocalPath);