將Unreal Engine項目發布使用之前,必須正確的打包,打包確保所有都是最新的,並能在對應平台上運行的正確格式。以 UE4.19 為例子
- Windows平台
創建包
然后選擇一個目錄,在UE4 工程右下方會有“正在打包”的提示
生成多個pak包
打包過程遇到的問題
1)Couldn't find parent type for 'K2Node_GetSequenceBinding' named 'UK2Node' in current module or any other module parsed so far
將myproject.Target.cs 原文件如下
修改為:
2)在測試的時候遇到一個錯誤,提示找不到“HeadMountedDisplayFunctionLibrary.h” 文件,
因為我的項目中用到了UE4.19中 “HeadMountedDisplay” ,vs生成的工程編譯沒問題,但是打包時,編譯報錯
所以需要在***.build.cs 文件中PublicDependencyModuleNames 中 添加 HeadMountedDisplay 庫
關於使用 “ProjectLauncher” 配置打包環境,在https://blog.csdn.net/zhangxiaofan666/article/details/79567017 中說明很詳細了,這里不再描述,感謝作者的總結
- Linux(Centos7)平台——打包server
UE4官方建議使用交叉編譯,但是我還是比較偏向於本地編譯,完全使用服務器的環境進行編譯打包,這只是個人的觀點。
安裝cmake & clang
cmake 要用3版本以上
clang安裝請參考我的另外一篇博文: https://www.cnblogs.com/KisonDu/p/10117262.html
UE4源碼安裝
1)yum 安裝ue4依賴包,否則源碼安裝會失敗
sudo yum install epel-release
sudo rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-1.el7.nux.noarch.rpm
wget http://copr.fedoraproject.org/coprs/jknife/ue4deps/repo/epel-7/jknife-ue4deps-epel-7.repo
sudo cp jknife-ue4deps-epel-7.repo /etc/yum.repos.d/jknife-ue4deps-epel-7.repo
sudo yum install steam vlc hexchat ntfs-3g mesa-libGLU libXScrnSaver
sudo yum install mono-core mono-devel dos2unix gtk3-devel
2)從github下載 UnrealEngine(github需要與unreal 做綁定,詳細請參考官網)
3)編譯安裝
cd UnrealEngine
./Setup.sh (這一步需要下載將近6G的包)
./GenerateProjectFiles.sh
make -j8 (注意:make的時候不能使用root用戶,否則會報錯,包含 打包工程都不能用root用戶)
此時就會在 Engine/Binaries/Linux 目錄下生成 UE4Editor 可執行文件
編譯打包
以下是寫的簡單的shell打包腳本,最重要的就是標紅的那一句,命令參數涵義跟windows是一樣的
#/bin/bash
type=server
platform=Linux
environment=Development
UATPath="/home/ue4/source/UnrealEngine/Engine/Build/BatchFiles/RunUAT.sh"
projectPath=$PWD
pmaps=ThirdPersonExampleMap
$UATPath BuildCookRun -project="$projectPath/RAN_Conqueror.uproject" -noP4 -platform=$platform -clientconfig=$environment -serverconfig=$environment -cook -build -server -nocompileeditor -compressed -stage -package -pak -compile -noclient -serverplatform=$platform -map=$pmaps -unversionedcookedcontent -createreleaseversion=1.0.0 -stagingdirectory="${projectPath}/package/server"
注意:官網上有這句話 If you haven't explicitly defined and set an environment variable of UE4_LINUX_USE_LIBCXX to 0, cross-compiling will use libc++ headers/libraries in there by default instead of the one inside the clang toolchain.
因為我的工程需要依賴其它的庫,所以我將UE4_LINUX_USE_LIBCXX 環境變量設置為0,使用我們指定clang而不使用ue4自帶的
- 補丁包打包方式
打補丁包是非常簡單的,只要設置下基礎版本號就可以了。
完整包打完之后,除了自己指定目錄下會生成最終的發布程序外,還會在.uproject 所在的目錄下生成Releases目錄,子目錄包含了所有完整版本的,如下:
這里主要介紹命令方式打補丁包。在命令行增加 -generatepatch -basedonreleaseversion=1.0.0 這兩個參數,去掉 -createreleaseversion 參數,
此時就會在輸出目錄中生成對應的補丁包,目前一個基本版本只會生成一個補丁版本,新的直接覆蓋舊的。
- 打包完整命令行
我自己比較習慣使用命令行方式打包,所以這里附上我平常工作中打包用到的命令行
RunUAT.bat -noP4 -client -platform=Win64 -clientconfig=Shipping -serverconfig=Shipping -cook -build -compressed -stage -package -pak -compile -map=map1+map2 -unversionedcookedcontent -createreleaseversion=1.0.0 -stagingdirectory=outdir
說明:1)補丁包將-createreleaseversion=1.0.0 替換成 -generatepatch -basedonreleaseversion=1.0.0
2)-client 表示打包client,-server表示打包server端
3) -platform 目前我用到有:PS4、Win64、Linux
4)-clientconfig -serverconfig 有:DebugGame、Development、Shipping
參考文檔
命令參數詳細介紹:http://wangjie.rocks/2018/08/09/ue4-uat-buildcookrun-cmd/
UE4官方打包文檔:http://api.unrealengine.com/CHN/Engine/Basics/Projects/Packaging/index.html
CSDN: https://blog.csdn.net/zhangxiaofan666/article/details/79567017
命令打包官方文檔:https://wiki.unrealengine.com/How_to_package_your_game_with_commands
Dedicated Server Guide (Windows & Linux):
https://wiki.unrealengine.com/Dedicated_Server_Guide_(Windows_%26_Linux)
https://wiki.unrealengine.com/index.php?title=Building_On_Linux