voidUAssetRegistryImpl::InitializeSerializationOptionsFromIni(FAssetRegistrySerializationOptions& Options, const FString& PlatformIniName)const { FConfigFile* EngineIni = nullptr; #if WITH_EDITOR // Use passed in platform, or current platform if empty FConfigFile PlatformEngineIni; FConfigCacheIni::LoadLocalIniFile(PlatformEngineIni, TEXT("Engine"), true, (!PlatformIniName.IsEmpty() ? *PlatformIniName : ANSI_TO_TCHAR(FPlatformProperties::IniPlatformName()))); EngineIni = &PlatformEngineIni; #else // In cooked builds, always use the normal engine INI EngineIni = GConfig->FindConfigFile(GEngineIni); #endif
/** Load/Save options used to modify how the cache is serialized. These are read out of the AssetRegistry section of Engine.ini and can be changed per platform. */ structFAssetRegistrySerializationOptions { /** True rather to load/save registry at all */ bool bSerializeAssetRegistry;
/** True rather to load/save dependency info. If true this will handle hard and soft package references */ bool bSerializeDependencies;
/** True rather to load/save dependency info for Name references, */ bool bSerializeSearchableNameDependencies;
/** True rather to load/save dependency info for Manage references, */ bool bSerializeManageDependencies;
/** If true will read/write FAssetPackageData */ bool bSerializePackageData;
/** True if CookFilterlistTagsByClass is a whitelist. False if it is a blacklist. */ bool bUseAssetRegistryTagsWhitelistInsteadOfBlacklist;
/** True if we want to only write out asset data if it has valid tags. This saves memory by not saving data for things like textures */ bool bFilterAssetDataWithNoTags;
/** True if we also want to filter out dependency data for assets that have no tags. Only filters if bFilterAssetDataWithNoTags is also true */ bool bFilterDependenciesWithNoTags;
/** Filter out searchable names from dependency data */ bool bFilterSearchableNames;
/** The map of classname to tag set of tags that are allowed in cooked builds. This is either a whitelist or blacklist depending on bUseAssetRegistryTagsWhitelistInsteadOfBlacklist */ TMap<FName, TSet<FName>> CookFilterlistTagsByClass;
/** Options used to read/write the DevelopmentAssetRegistry, which includes all data */ voidModifyForDevelopment() { bSerializeAssetRegistry = bSerializeDependencies = bSerializeSearchableNameDependencies = bSerializeManageDependencies = bSerializePackageData = true; DisableFilters(); }
voidUAssetRegistryImpl::InitializeSerializationOptionsFromIni(FAssetRegistrySerializationOptions& Options, const FString& PlatformIniName)const { FConfigFile* EngineIni = nullptr; #if WITH_EDITOR // Use passed in platform, or current platform if empty FConfigFile PlatformEngineIni; FConfigCacheIni::LoadLocalIniFile(PlatformEngineIni, TEXT("Engine"), true, (!PlatformIniName.IsEmpty() ? *PlatformIniName : ANSI_TO_TCHAR(FPlatformProperties::IniPlatformName()))); EngineIni = &PlatformEngineIni; #else // In cooked builds, always use the normal engine INI EngineIni = GConfig->FindConfigFile(GEngineIni); #endif
{ // this only needs to be done once, and only on builds using USE_COMPACT_ASSET_REGISTRY TArray<FString> AsFName; EngineIni->GetArray(TEXT("AssetRegistry"), TEXT("CookedTagsAsFName"), AsFName); TArray<FString> AsPathName; EngineIni->GetArray(TEXT("AssetRegistry"), TEXT("CookedTagsAsPathName"), AsPathName); TArray<FString> AsLocText; EngineIni->GetArray(TEXT("AssetRegistry"), TEXT("CookedTagsAsLocText"), AsLocText); FAssetRegistryState::IngestIniSettingsForCompact(AsFName, AsPathName, AsLocText); } // ... }
在打包时可以在 Project Settings-Packaging 中设置 Share Material Shader Code 和Shadred Material Native Libraries可以减小包体的大小,并且会减少内存占用(增加加载时间)。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/** * By default shader code gets saved inline inside material assets, * enabling this option will store only shader code once as individual files * This will reduce overall package size but might increase loading time */ UPROPERTY(config, EditAnywhere, Category=Packaging) bool bShareMaterialShaderCode;
/** * By default shader shader code gets saved into individual platform agnostic files, * enabling this option will use the platform-specific library format if and only if one is available * This will reduce overall package size but might increase loading time */ UPROPERTY(config, EditAnywhere, Category=Packaging, meta = (EditCondition = "bShareMaterialShaderCode", ConfigRestartRequired = true)) bool bSharedMaterialNativeLibraries;
boolFWidgetBlueprintCompilerContext::CanAllowTemplate(FCompilerResultsLog& MessageLog, UWidgetBlueprintGeneratedClass* InClass) { // ... // If this widget forces the slow construction path, we can't template it. if (WidgetBP->bForceSlowConstructionPath) { if (GetDefault<UUMGEditorProjectSettings>()->CompilerOption_CookSlowConstructionWidgetTree(WidgetBP)) { MessageLog.Note(*LOCTEXT("ForceSlowConstruction", "Fast Templating Disabled By User.").ToString()); returnfalse; } else { MessageLog.Error(*LOCTEXT("UnableToForceSlowConstruction", "This project has [Cook Slow Construction Widget Tree] disabled, so [Force Slow Construction Path] is no longer allowed.").ToString()); } } // ... }
关闭 pakcache
引擎中默认启用了 PakCache 机制,在从 Pak 中读取文件时,会多读一段内存用作缓存,内存占用还是十分可观的(通过 stat memory 查看):
if ((bUnloadPakEntryFilenamesIfPossible && !FParse::Param(FCommandLine::Get(), TEXT("nounloadpakentries"))) || FParse::Param(FCommandLine::Get(), TEXT("unloadpakentries"))) { // With [Pak] UnloadPakEntryFilenamesIfPossible enabled, [Pak] DirectoryRootsToKeepInMemoryWhenUnloadingPakEntryFilenames // can contain pak entry directory wildcards of which the entire recursive directory structure of filenames underneath a // matching wildcard will be kept. // // Example: // [Pak] // DirectoryRootsToKeepInMemoryWhenUnloadingPakEntryFilenames="*/Config/Tags/" // +DirectoryRootsToKeepInMemoryWhenUnloadingPakEntryFilenames="*/Content/Localization/*" TArray<FString> DirectoryRootsToKeep; GConfig->GetArray(TEXT("Pak"), TEXT("DirectoryRootsToKeepInMemoryWhenUnloadingPakEntryFilenames"), DirectoryRootsToKeep, GEngineIni);
当调用之后,如果开启 UnloadPakEntryFilenamesIfPossible 了,会通过计算 Pak 中文件名列表的 Hash 来节省内存,但是卸载 PakEntry filenames 之后无法再使用路径的通配符匹配。
Runtime\PakFile\Public\IPlatformFilePak.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/** Iterator class used to iterate over all files in pak. */ classFFileIterator { // ... /** * Saves memory by hashing the filenames, if possible. After this process, * wildcard scanning of pak entries can no longer be performed. Returns TRUE * if the process successfully unloaded filenames from this pak * * @param CrossPakCollisionChecker A map of hash->fileentry records encountered during filename unloading on other pak files. Used to detect collisions with entries in other pak files. * @param DirectoryRootsToKeep An array of strings in wildcard format that specify whole directory structures of filenames to keep in memory for directory iteration to work. * @param bAllowRetries If a collision is encountered, change the intial seed and try again a fixed number of times before failing */ boolUnloadPakEntryFilenames(TMap<uint64, FPakEntry>& CrossPakCollisionChecker, TArray<FString>* DirectoryRootsToKeep = nullptr, bool bAllowRetries = true); };