Cook

Cook 流程

会执行到 UCookCommandlet 的 main 中: Source\Editor\UnrealEd\Private\Commandlets\CookCommandlet.cpp

参考: https://rootjhon.github.io/posts/%E8%B5%84%E6%BA%90Cook%E6%9E%84%E5%BB%BA/

Cook Content

https://docs.unrealengine.com/5.3/zh-CN/cooking-content-in-unreal-engine/

https://docs.unrealengine.com/5.3/zh-CN/build-operations-cooking-packaging-deploying-and-running-projects-in-unreal-engine/

命令行启动

测试命令:

1
 .\UnrealEditor-Cmd.exe E:\Work\xxx\xxx.uproject -run=cook -targetplatform=Windows -map=/Game/TestMap

这里的 .\ 一定需要,目录在项目路径的 Engine\Binaries\Win64 中

测完会放在项目目录的 Saved\Cooked\Windows\ 中。

编辑器与IDE下启动

编辑器下,我们可以点击cook:

此时 Output Log 会有对应 Commandlet(这里的 xxx 是你的项目路径):

1
E:\Work\xxx\Engine\Binaries\Win64\UnrealEditor-Cmd.exe E:\Work\xxxxxxx\C7.uproject -run=Cook  -TargetPlatform=Windows  -unversioned -fileopenlog -abslog=E:\Work\xxx\Engine\Programs\AutomationTool\Saved\Cook-2023.11.28-15.04.02.txt -stdout -CrashForUAT -unattended -NoLogTimes  -UTF8Output

我们可以把对应参数填入 UE5 项目参数中进行调试:

此时对于贴图的 Cook 的调用栈为:

可能的分支:

参数

-iterate:以 Windows 为例,会存到 Saved\Cooked\Windows\项目名字\Content\相同路径下, 例如一个关卡 /Game/Test1/HbhTest.umap, 则会生成对应两个文件: Saved\Cooked\Windows\项目名字\Content\Test1\HbhTest.uexp, Saved\Cooked\Windows\项目名字\Content\Test1\HbhTest.umap;这个参数会比较创建的时间戳,如果需要更新则会重新cook; 因此如果本地删除这两个文件,用 -iterate 参数即会重新 cook

-skipeditorcontent:在 CookOnTheFlyServer 中会忽略 /Engine/Editor* 与 /Editor/VREditor* 中的资源

1
2
3
4
5
6
7
8
// don't save Editor resources from the Engine if the target doesn't have editoronly data
if (IsCookFlagSet(ECookInitializationFlags::SkipEditorContent) &&
	(PackagePathName.StartsWith(TEXT("/Engine/Editor")) || PackagePathName.StartsWith(TEXT("/Engine/VREditor"))) &&
	!Target->HasEditorOnlyData())
{
	Result = ESavePackageResult::ContainsEditorOnlyData;
	bCookPackage = false;
}

打包逻辑

UE 打包时加载资源的思路是:先找到本地 uasset 文件,将路径转换为 PackageName,进行加载,在加载时会把依赖的资源也加载了,然后将其一起 Cook。

参考: https://imzlp.com/posts/22570/

Licensed under CC BY-NC-SA 4.0