Automated nightly builds in UE4

March 11th, 2019

Spoiler alert: this post is going to wind up sounding a lot like an advertisement for Shadow but none of the things I’m doing are specific to Shadow.

So the other day I was talking with my brother and he mentioned that he had recently started using Shadow, a streaming high-end PC gaming platform. He seemed to really like it and mentioned that you get your own dedicated virtual box and not just a front end to some gaming system. That part really intrigued me.

I’m getting to the point in one of my projects where the
building times for getting good lighting are really killing me. I had looked into automating that process but even if I did I’d rather not have it taking my development machine out of commission to do so.

So this is the part that really interested me in shadow. If I could set up a nightly task on a shadow machine to check out my latest code and do a full lighting build and all, that would be well worth the price to me that shadow was charging. So I looked into it and not only was it possible it was relatively easy to pull off.

To accomplish this I created a new folder inside my project directory called “Automation” and I created 4 .bat files inside of that.

I split the workload into 3 separate files because there’s a good chance that as I work on this I’m going to be making changes to the build lighting file. By separating that one from the update from git command I can check in without needing to worry about a file overwriting itself . There’s 3 main tasks to get this built correctly.

  1. Pull from Git
  2. Build the lighting
  3. Build the playable executable

Pulling from git: This part should be straight forward enough. I want to pull the newest files from git and blow out any changes I may have locally. As I don’t develop on the shadow machine this shouldn’t be a problem. DO NOT DO THIS IF YOU ARE STTING THIS UP N A DEVELOPMENT MACHINE. So my UpdateFromGit.bat file looks something like this:

git reset --hard origin/master
git pull origin master

Building the lighting: Most of the functionality unreal uses to build your project is available from the command line. After a little bit of google-fu I was able to come up with the following code snippet to build the lighting for each of my maps. Currently there’s only one line because I’m only building one map, but I expect this file to grow as I start including more maps.

REM Gameplay_Proto Map
"C:\Program Files\Epic Games\UE_4.21\Engine\Binaries\Win64\UE4Editor-Cmd.exe" "C:\Projects\GitRepos\MilosManyNightmares\MMN.uproject" -run=resavepackages -buildlighting -quality=Production -allowcommandletrendering -map=Gameplay_Proto

The above is my specific Build_Lighting.bat file. Yours is likely to have different values but as long as it follows this format is should work fine.

(Path to UE4Editor-Cmd.exe) (Path to your project file) -run=resavepackages -buildlighting -quality=Production -allowcommandletrendering -map=(Name of map you want to build the lighting for)

The REM line at the top is just comment to myself so I know what line corresponds to what map at a glance.

Building the playable executable: So the command line for this is actually pretty complicated. Luckily enough Unreal comes with a tool that will build that command line for you. If you open up a project and then click on the window panel you should see an option for “Project Launcher”

Once in that window you’ll see an option to create a new profile. Go ahead and create one.

Inside you’ll see a series of options. I highly recommend reading the actual dcumentation for this section( https://docs.unrealengine.com/en-US/Engine/Deployment/BuildOperations ) but for now here’s the cliff notes of how to fill it out.

  • Project
    • Browse to the project you want to build
  • Build
    • Check the build checkbox
  • Cook
    • Switch the option to “By the book”
    • choose your platform and culture
    • Select which maps to cook.
  • Package
    • Switch the option to package and store locally and give it an output directory to put your build.
  • Archive
    • Don’t archive
  • Deploy
    • Don’t deploy

Once that’s done try launching the profile to make sure your project builds correctly.

If you notice the highlighted line starts with “parsing command line”. Use the button at the bottom to copy that line and insert it into your text editor. Remove everything before the words BuildCookRun and replace them with the path to your RunUAT.bat file, ususally located at (UE4folder)\Engine\Build\BatchFiles\RunUAT.bat .

Create simple batch file to run the others: After all that all you have to do is create a simple .bat file to call the other 3. Mine looks like this:

call UpdateFromGit.bat
call Build_Lighting.bat
call Build_Executable.bat

And that’s about it. After that you can just create a scheduled windows task or if you don’t have admin privileges on the machine use any third party scheduler to call the build_all.bat file some time in the night.

So here comes the shameless shadow plug. I’ve found that offloading this to my shadow is a really nice and clean way to accomplish this task, pus it allows me to do all the other shadow stuff when it’s not building like play games anywhere. If you are interested in giving it a try please use my refer-a-friend code ( ROBU3USP ) and we’ll both get $10 bucks off. Either way I hope this post helps.

back to blog