Skip to main content

Unreal Engine 5 Automation Build

✍ Last Updated : August 30, 2022

🚪 Prerequisite Knowledge (Optional)

Unreal Build Operation

[Unreal Engine 5 Build Operations](Unreal Engine 5 Build Operations 7860d2fed8f2484aa7c7afd641e1594d.md)

❓ Key Question / Problem / Issue

Describe what question / Problem / Issue this knowledge should answer

✅ Expected Output/Definition of Done

Define what information you really need and the definition of done

🎁 Resulting Solution

Source

AutomationTool Overview

ue4-unreal-automation-tool/README.md at main · botman99/ue4-unreal-automation-tool

Unreal Automation Tools (UAT)

Before we start the automation build Unreal Engine 5 project, we should know what tool that we’ll use. AutomationTool is a host program and a set of utility libraries you can use to script unattended processes related to Unreal Engine (UE) ****when using C#. Internally, we use AutomationTool for a variety of tasks, including building, cooking, and running games, running automation tests, and scripting other operations to be executed on our build farm.

How to Run UAT?

To run UAT, there is a RunUAT.bat file (windows) in the Engine/Build/BatchFiles folder. When running UAT, you need to be in the Unreal Engine root folder or in the Engine/Build/BatchFiles folder. If you installed using the Epic Games Launcher, that will be something like C:\Program Files\Epic Games\UE_5.0. You should see the /Engine folder contained in root folder.

At command prompt / cmd:

C:\Program Files\Epic Games\UE_4.50>Engine\Build\BatchFiles\RunUAT.bat

Normally, it should be error / failed to build. Its error because we didn't give UAT a valid command to execute. To check full list of command, you can add -List while run the RunUAT.bat file.

Engine\Build\BatchFiles\RunUAT.bat -List

AnalyzeThirdPartyLibs     CleanDevices                     RebasePublicIncludePaths     TestKillAll
BenchmarkBuild            CleanFormalBuilds                RebuildHLOD                  TestLog
BenchmarkOptions          CleanTempStorage                 RebuildLightMaps             TestMacZip
BlameKeyword              CodeSurgery                      RecordPerformance            TestMcpConfigs
Build                     CopySharedCookedBuild            ReplaceAssetsUsingManifest   TestMessage
BuildCMakeLib             CopyUAT                          ResavePackages               TestOSSCommands
BuildCommonTools          CryptoKeys                       ResavePluginDescriptors      TestP4_ClientOps
BuildCookRun              DebugSleep                       ResaveProjectDescriptors     TestP4_CreateChangelist
BuildDerivedDataCache     DumpBranch                       RunEditorTests               TestP4_Info
BuildEditor               ExportIPAFromArchive             RunP4Reconcile               TestP4_LabelDescription
BuildForUGS               ExportMcpTemplates               RunUnreal                    TestP4_StrandCheckout
BuildGame                 ExtractPaks                      StashTarget                  TestRecursion
BuildGraph                FinalizeInstalledBuild           SubmitUtilizationReportToEC  TestRecursionAuto
BuildHlslcc               FixPerforceCase                  SyncBinariesFromUGS          TestStopProcess
BuildPhysX                FixupRedirects                   SyncDDC                      TestSuccess
BuildPlugin               GenerateAutomationProject        SyncDepotPath                TestTestFarm
BuildServer               GenerateDSYM                     SyncProject                  TestThreadedCopyFiles
BuildTarget               GitPullRequest                   SyncSource                   TestUATBuildProducts
BuildThirdPartyLibs       IPhonePackager                   TempStorageTests             UBT
CheckBalancedMacros       ListMobileDevices                TestArguments                UE4BuildUtilDummyBuildCommand
CheckCsprojDotNetVersion  ListThirdPartySoftware           TestBlame                    UnstashTarget
CheckForHacks             Localise                         TestChangeFileType           UpdateLocalVersion
CheckPerforceCase         Localize                         TestChanges                  UploadDDCToAWS
CheckRestrictedFolders    LookForOverlappingBuildProducts  TestCleanFormalBuilds        WriteIniValueToPlist
CheckTargetExists         MegaXGE                          TestCombinePaths             ZipProjectUp
CheckXcodeVersion         OpenEditor                       TestFail                     ZipUtils
CleanAutomationReports    P4WriteConfig                    TestFileUtility
CleanDDC                  ParseMsvcTimingInfo              TestGauntlet

Automation Build

To begin automate the game, We should create a Windows batch file called build.bat that needs to be placed in the Unreal Engine root folder (where you have Unreal Engine installed on your machine). If you are using an installed build, installed from the Epic Games Launcher, the default location of the root folder will be the C:\Program Files\Epic Games\UE_5.0 folder.

build.bat script**:**

@echo off

REM - This batch file will build the editor and game code for your Unreal Engine project.

REM - Replace MyAwesomeGame with the name of your project here!!!
set PROJECT_NAME=Automation_UE5
set ENGINE_PATH=C:\Program Files\Epic Games\UE_5.0
set BATCH_FILES_PATH=%ENGINE_PATH%\Engine\Build\BatchFiles

cd /d "%ENGINE_PATH%"

if exist "%ENGINE_PATH%" echo "%ENGINE_PATH%"
echo "%~dp0%PROJECT_NAME%.uproject"

REM - Set MAPS to the list of maps you want to cook, for example "MainMenuMap+FirstLevel+SecondLevel+TestMap" (DO NOT PUT SPACES ANYWHERE HERE!!!)
set MAPS=

if exist "%~dp0%PROJECT_NAME%.uproject" goto Continue

echo.
echo Warning - "%~dp0%PROJECT_NAME%."uproject does not exist!
echo (edit this batch file in a text editor and set PROJECT_NAME to the name of your project)
echo.

pause

goto Exit

:Continue

if exist BUILD_EDITOR_FAILED.txt del BUILD_EDITOR_FAILED.txt
if exist BUILD_GAME_FAILED.txt del BUILD_GAME_FAILED.txt
if exist PACKAGING_FAILED.txt del PACKAGING_FAILED.txt

if NOT "%MAPS%"=="" (goto CheckInstalledBuild)

echo.
echo Warning - You don't have MAPS set, this will cause ALL content to be cooked!
echo (potentially making your packaged build larger than it needs to be)
echo.

:CheckInstalledBuild

REM - We need to check if this is an "Installed Build" (i.e. installed from the Epic Launcher) or a source code build (from GitHub).
if exist "Engine\Build\InstalledBuild.txt" (
    set INSTALLED=-installed
) else (
    set INSTALLED=
)

echo  "%~dp0Source"
echo "Engine\Build\BatchFiles\RunUAT.bat BuildGame -project="%~dp0%PROJECT_NAME%.uproject" -platform=Win64 -notools -configuration=Development+Shipping+DebugGame"
REM - Check if a .sln file exists for the project, if so, then it is a C++ project and you can build the game editor (otherwise it's a Blueprint project).
if exist "%~dp0Source" (
    echo.
    echo %date% %time% Building Game Editor...
    echo.

    call Engine\Build\BatchFiles\RunUAT.bat BuildEditor -Project="%~dp0%PROJECT_NAME%.uproject" -notools
    if errorlevel 1 goto Error_BuildEditorFailed

    echo.
    echo %date% %time% Building Game...
    echo.

    call Engine\Build\BatchFiles\RunUAT.bat BuildGame -project="%~dp0%PROJECT_NAME%.uproject" -platform=Win64 -notools -configuration=Development+Shipping+DebugGame
    if errorlevel 1 goto Error_BuildGameFailed
)

echo %date% %time% Packaging the game...

REM - Note: "-clean" will clean and rebuild your game code (for C++ projects) and will clean the project's Saved\Cooked and Saved\StagedBuilds for every time this runs
REM - Note: If you don't wish to fully rebuild your game code each time you package, you can add "-nocompile" to skip compiling game code.
REM - Note: "-pak" will store all cooked content into a .pak file (using the UnrealPak tool).  Packaged games can (optionally) use encrypted .pak file for better security.
REM - Note: When you are ready to ship your game, change -configuration to just "-configuration=Shipping" (to prevent including Development and DebugGame executables in your shipped build).
REM - Note: When you are ready to ship your game, add "-nodebuginfo" to prevent the .pdb file from being added to the game's Binaries/Win64 folder.
REM - Note: Using "-createreleaseversion" allows you to create Patches and DLC later for your game if you wish.
REM - Note: You can use "-compressed" if you want to compress packages (this will make files smaller, but may take longer to load in game).

call Engine\Build\BatchFiles\RunUAT.bat BuildCookRun -project="%~dp0%PROJECT_NAME%.uproject" %INSTALLED% -platform=Win64 -configuration=Development+Shipping+DebugGame -map=%MAPS% -nocompileeditor -unattended -utf8output -nodebuginfo -clean -build -cook -stage -stagingdirectory="%~dp0/Temp/Stage" -pak -prereqs -package -createreleaseversion=1.0
if errorlevel 1 goto Error_PackagingFailed

echo.
echo %date% %time% Done!

echo.
echo %date% %time% Done!

goto Exit

:Error_BuildEditorFailed
echo.
echo %date% %time% Error - Build Editor failed!
type NUL > BUILD_EDITOR_FAILED.txt
goto Exit

:Error_BuildGameFailed
echo.
echo %date% %time% Error - Build Game failed!
type NUL > BUILD_GAME_FAILED.txt
goto Exit

:Error_PackagingFailed
echo.
echo %date% %time% Error - Packaging failed!
type NUL > PACKAGING_FAILED.txt
goto Exit

:Exit
cd /d "%~dp0"

After build.bat is created. We need to edit the PackageGame.bat file in a text editor to set it up for your project. Near the top of the file, you will see this line:

set PROJECT_NAME=MyAwesomeGame
set ENGINE_PATH=C:\Program Files\Epic Games\UE_5.0

At PROJECT_NAME, replace with your project name (check your .uproject file name).

At ENGINE_PATH, if you not, use default installation path, replace with your Unreal Engine root path.

If you want to indicate specific maps to cook, you can edit the build.bat file and look for the following line:

set MAPS=

Here you want to specify a list of maps to cook and stage by providing the name of the map files separated by a '+' sign (but don't use ANY SPACES), like so:

set MAPS=MainMenuMap+FirstLevel+SecondLevel+TestMap

You can test to run the build.bat batch file by just double clicking on it in Windows Explorer. If everything runs correctly, in your Unreal Project folder you should find two new folders, "Temp" and "Releases".

Inside the Temp folder will be new Stage folder that contains Packaged game. Inside the Windows folder will be your packaged/executable(s) game and ready to run. You can double click on the executables in that folder to run the game. There’s three executables files, “[project name]+.exe”, “[project name] + -platform-DebugGame.exe”, and “[project name] + -platform-Shipping.exe”. This is because we set the configuration for Development, Shipping and Debug Game for the same time. You can change the configuration if it’s not necessary for your project.

// current configuration
-configuration=Development+Shipping+DebugGame

// if you only need to development, change to this
-configuration=Development

Inside the Releases folder will be a folder name for the release version of this packaged build (in this case "1.0"). This is used if you want to release Patches or DLC for your game.

Automation Build on Gategit

You can also use CI/CD Pipelines at gategit to run the automation build. To run the pipeline, you will need .gitlab-ci.yaml, gitlab CI configuration files. Because we already did all of the automation configuration at batch file (build.bat), we only need to call the build.batat .gitlab-ci.yaml:

variables:
    GIT_CLEAN_FLAGS: -x -f -e ./**
    # (Win64,HoloLens,Mac,IOS,Android,Linux,LinuxArm64,TVOS)
    # BUILD_TARGET: Win64+Android
    BUILD_TARGET: Win64

stages:
    - build

windows-build:
    stage: build
    before_script:
        - git lfs install
        - git lfs checkout
    script:
        - FOR /F "tokens=*" %%a in ('cd') do SET PROJECT_PATH=%%a
        - ECHO %PROJECT_PATH%
        - |
            ./build.bat
    when: manual
    artifacts:
        paths:
            - Temp/Stage
    tags:
        - windows

Save the .gitlab-ci.yaml at root of your project.

Go to your repository, CI/Cd → Pipelines.

Untitled

There’s list all of commit’s pushed to the project. At your commit, you will see ‘>>’ symbol at Stages, click it. You’ll see list of pipelines stages (at this point only windows-build just like on our .gitlab-ci.yaml script, *may add another build platform later). Run the automation build with click the play button at windows-build stages.

Untitled

Once it passed, the pipelines status and stages would change and you can download the build as artifact by clicking the three dot point at the right side.

Untitled