Jekyll2023-06-17T21:20:54+10:00https://jackknobel.com/feed.xmlJack KnobelCoding Experiments and PredicamentsJack KnobelBuilding an Installed version of UE42017-02-06T00:00:00+11:002017-02-06T00:00:00+11:00https://jackknobel.com/buildgraph/2017/02/06/Building-an-installed-ue4-from-source<h1 id="why-an-installed-build">Why an Installed Build?</h1>
<p>Recently I’ve come across the need to start using the source version of UE4 again. The last time I used it was for some contract work earlier last year. It worked well but it had some fundamental issues that prevented me from using it on my main project up until now:</p>
<ol>
<li>More difficult than a one-click install for non-technical folk to use</li>
<li>A lot more of a pain to update</li>
<li>Distribution to the rest of the team as its no longer <em>“done for us”</em></li>
</ol>
<p>This time around I wanted to actually address these issues and I guess this gave me an excuse to dive into the build system of UE4. The solution to my problem was creating an installed version of the engine <em>(although, funnily enough after writing this article we’ve switched production pipelines but that is a story for another day).</em></p>
<p>When I refer to an <em>Installed Build</em> what I mean is a binary build, a build that is ready for distribution. An example of this is the one you download from the Unreal Engine Launcher.</p>
<p>Before we dive into this there are a couple of things to note.</p>
<p>First up, unfortunately if you are on UE version 4.12 or earlier this write up won’t be of any help to you, as the Build Graph system was only published in 4.13. But fear not, <a href="https://github.com/Kalmalyzer/">Kalmalyzer</a> has your back with his <a href="https://github.com/Kalmalyzer/UE4RocketBuild">UE4 Rocket Build Tutorial</a>.</p>
<p>Secondly, before jumping into this article I’d highly suggest you take a read of my other article <a href="/How-To/BuildGraph">How To: BuildGraph</a>. As that article, will give you some deeper insight into what the hell this all means.</p>
<h1 id="building-the-installed-build">Building the Installed Build</h1>
<p>Assuming you have read my previous article or know what you’re doing then you should have the source version of Unreal set up and ready to go.</p>
<p>To build an Installed Build all we simply need to do is call UAT with the BuildGraph command, set our target to be our platform, and then give it the path to the Installed Engine Build script.</p>
<div class="language-sh highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="s2">"[EnginePath]/Engine/Engine/Build/BatchFiles/RunUAT.bat"</span> BuildGraph <span class="nt">-target</span><span class="o">=</span><span class="s2">"Make Installed Build Win64"</span> <span class="nt">-script</span><span class="o">=</span><span class="s2">"[EnginePath]/Engine/Build/InstalledEngineBuild.xml"</span> <span class="nt">-clean</span>
</code></pre></div></div>
<p>The <code class="language-plaintext highlighter-rouge">-clean</code> value is optional and will result in a full rebuild as opposed to continuing from where it left off. If you are planning on doing iterative builds then you can remove it, however, if you are wanting to ensure everything compiles then I’d recommend keeping it.</p>
<p>If Windows is not your desired platform for the editor it also supports both Mac and Linux via <code class="language-plaintext highlighter-rouge">Make Installed Build Mac</code> and <code class="language-plaintext highlighter-rouge">Make Installed Build Linux</code> respectively.</p>
<p>By default, the call above will include the following target platforms; Win64, Win32, Mac, Linux Android, IOS, TVOS and HTML5. Each of these add to the build time so if you are wanting to reduce your build times you can set the host platform only option <code class="language-plaintext highlighter-rouge">-set:HostPlatformOnly=true</code> which, as its name suggests will only compile for your current pc’s platform.</p>
<p>An additional optimization you can make is by disabling <a href="https://docs.unrealengine.com/latest/INT/Engine/Basics/DerivedDataCache/index.html">Derived-Data Cache</a> generation which, if left on, can add quite some time to your build (I also wouldn’t recommend this as well if you are planning on sharing this build over the internet especially if via source control).</p>
<p>After running the script your build should appear in your root engine folder under <code class="language-plaintext highlighter-rouge">LocalBuilds/[EditorTarget]</code>. At the time of writing this I could not use the built-in commands to change the output directory. Instead I had to resort to adding an option that allows you to do so; you can check that out down <a href="#changing-the-output-directory">below</a>.</p>
<h1 id="extending-the-build-script">Extending the Build Script</h1>
<h3 id="adding-dedicated-server-target-support">Adding Dedicated Server Target support</h3>
<p>Typically, something you can only do in the source version, adding dedicated server support to your installed version in reality is really easy. All we need to do is make some small adjustments to our <em>InstalledEngineBuild.xml</em> file (Found in <code class="language-plaintext highlighter-rouge">[EnginePath]/Engine/Build/InstalledEngineBuild.xml</code>)</p>
<p>The first change is to add the target to the compilation list. The following code is placed under the UE4Game Target section which is you will find in the <code class="language-plaintext highlighter-rouge">Target Platfoms Win64</code> agent.</p>
<div class="language-xml highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c"><!-- UE4 Server Target Compile Tasks --></span>
<span class="nt"><Compile</span> <span class="na">Target=</span><span class="s">"UE4Server"</span> <span class="na">Platform=</span><span class="s">"Win64"</span> <span class="na">Configuration=</span><span class="s">"Development"</span> <span class="na">Tag=</span><span class="s">"#UE4Game Win64"</span> <span class="na">Arguments=</span><span class="s">"-precompile -nodebuginfo"</span><span class="nt">/></span>
<span class="nt"><Compile</span> <span class="na">Target=</span><span class="s">"UE4Server"</span> <span class="na">Platform=</span><span class="s">"Win64"</span> <span class="na">Configuration=</span><span class="s">"Shipping"</span> <span class="na">Tag=</span><span class="s">"#UE4Game Win64"</span> <span class="na">Arguments=</span><span class="s">"-precompile -nodebuginfo"</span><span class="nt">/></span>
</code></pre></div></div>
<p>This section is just like the UE4Game target adds the UE4Server target to our build for both development and shipping build configurations. The files are tagged as the tagged files are used later down the line for further use.</p>
<p>Lastly, we want to add the follow line of code to just under the corresponding UE4Game code in the same agent as above (should only be a few lines down).</p>
<div class="language-xml highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c"><!-- Ouput directory for the build --></span>
<span class="nt"><Tag</span> <span class="na">Files=</span><span class="s">"Engine/Intermediate/Build/Win64/UE4Server/Inc/...;Engine/Plugins/.../Intermediate/Build/Win64/UE4Server/Inc/..."</span> <span class="na">With=</span><span class="s">"#UE4Game Win64 Includes"</span><span class="nt">/></span>
</code></pre></div></div>
<p>That’s it! After compiling the engine, you should now have the ability to compile a dedicated server target for your game in editor and in visual studio with your installed engine. How great is that?!</p>
<p>The logic we have done here should in fact also apply for both Linux and Mac as well, as long as you follow the same procedure and change the respective targets, platforms etc.</p>
<h3 id="changing-the-output-directory">Changing the output directory</h3>
<p>As I eluded too earlier I had issues using the built-in method of outputting the compiled engine to a desired directory. What I’m going to show you now is a super easy way to add the ability to do this. We just need to do two simple things;</p>
<p>First of all we create ourselves an option:</p>
<div class="language-xml highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c"><!-- Ouput directory for the build --></span>
<span class="nt"><Option</span> <span class="na">Name=</span><span class="s">"BuiltDirectory"</span> <span class="na">DefaultValue=</span><span class="s">"$(RootDir)/LocalBuilds/Engine/"</span> <span class="na">Description=</span><span class="s">"Directory for outputting the built engine"</span><span class="nt">/></span>
</code></pre></div></div>
<p>Then we change the following bit of code from:</p>
<div class="language-xml highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c"><!-- The local output directory --></span>
<span class="nt"><Property</span> <span class="na">Name=</span><span class="s">"LocalInstalledDir"</span> <span class="na">Value=</span><span class="s">"$(RootDir)/LocalBuilds/Engine/Windows"</span><span class="nt">/></span>
<span class="nt"><Property</span> <span class="na">Name=</span><span class="s">"LocalInstalledDirMac"</span> <span class="na">Value=</span><span class="s">"$(RootDir)/LocalBuilds/Engine/Mac"</span><span class="nt">/></span>
<span class="nt"><Property</span> <span class="na">Name=</span><span class="s">"LocalInstalledDirLinux"</span> <span class="na">Value=</span><span class="s">"$(RootDir)/LocalBuilds/Engine/Linux"</span><span class="nt">/></span>
</code></pre></div></div>
<p>to:</p>
<div class="language-xml highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c"><!-- The local output directory --></span>
<span class="nt"><Property</span> <span class="na">Name=</span><span class="s">"LocalInstalledDir"</span> <span class="na">Value=</span><span class="s">"$(BuiltDirectory)/Windows"</span><span class="nt">/></span>
<span class="nt"><Property</span> <span class="na">Name=</span><span class="s">"LocalInstalledDirMac"</span> <span class="na">Value=</span><span class="s">"$(BuiltDirectory)/Mac"</span><span class="nt">/></span>
<span class="nt"><Property</span> <span class="na">Name=</span><span class="s">"LocalInstalledDirLinux"</span> <span class="na">Value=</span><span class="s">"$(BuiltDirectory)/Linux"</span><span class="nt">/></span>
</code></pre></div></div>
<p>Now all we need to do is add <code class="language-plaintext highlighter-rouge">-set:BuiltDirectory="C:/MyCompiledEngine/"</code> to the BuildGraph call.</p>
<p>The resulting call should look something like this:</p>
<div class="language-sh highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="s2">"[EnginePath]/Engine/Engine/Build/BatchFiles/RunUAT.bat"</span> BuildGraph <span class="nt">-target</span><span class="o">=</span><span class="s2">"Make Installed Build Win64"</span> <span class="nt">-script</span><span class="o">=</span><span class="s2">"[EnginePath]/Engine/Build/InstalledEngineBuild.xml"</span> <span class="nt">-clean</span> <span class="nt">-set</span>:BuiltDirectory<span class="o">=</span><span class="s2">"C:/MyCompiledEngine/"</span>
</code></pre></div></div>
<p>Voila your built engine should appear in the specified folder after it’s finished compiling.</p>
<p>Now you should have everything you need to build your own binary version of the engine. I would highly recommend reading through the entirety of the <em>InstalledEngineBuild.xml</em> to see some more advanced BuildGraph features in action. Additionally, be sure to check out my previous post <a href="/How-To/BuildGraph">How To: BuildGraph</a> so you can learn how to add functionality for yourself.</p>
<p>That’s everything for this post, you can find a copy of the full modified <em>InstalledEngineBuild.xml</em> file down below as well as links to all the posts/articles that helped me along the way. If you any questions, feel free to leave a comment or shoot me a tweet <a href="https://twitter.com/jack_knobel">@jack_knobel</a>.</p>
<h1 id="useful-links">Useful Links</h1>
<ul>
<li><a href="https://forums.unrealengine.com/showthread.php?125033-How-to-create-Rocket-build-that-can-deploy-Dedicated-Server-of-game&p=645258#post645258">Distributed Build with Dedicated Server target</a></li>
<li><a href="https://forums.unrealengine.com/showthread.php?123490-Current-advice-for-distributing-custom-engine-builds-to-team-without-recompiling">Distributing Custom Engine Build</a></li>
<li><a href="https://docs.unrealengine.com/latest/INT/Programming/Development/BuildGraph/Usage/index.html">Build Graph Usage</a></li>
</ul>
<h3 id="files">Files</h3>
<p><a href="https://jackknobel.com/files/posts/BuildingInstalledEngine/InstalledEngineBuild.xml">InstalledEngineBuildModified.xml</a></p>Jack KnobelWhy an Installed Build?How To: BuildGraph2017-01-03T00:00:00+11:002017-01-03T00:00:00+11:00https://jackknobel.com/How-To/how-to-buildgraph<h1 id="what-is-buildgraph">What is BuildGraph?</h1>
<p>BuildGraph is a script-based build system that has been integrated into the Unreal build pipeline as of 4.13. The core selling point of BuildGraph is that it gives developers more flexibility in how they go about generating specific outputs from <a href="https://docs.unrealengine.com/latest/INT/Programming/UnrealBuildSystem/">UBT (Unreal Build Tool)</a>. If you have used makefiles before or setup a build farm then you should be right at home with this system, as it is basically a combination of the two systems.</p>
<p>BuildGraphs consist of one major component; the BuildGraph script. A BuildGraph script is an XML document that uses a custom schema to define how to process and handle the content found within it. As found in the <a href="https://docs.unrealengine.com/latest/INT/Programming/Development/BuildGraph/index.html#writingbuildgraphscripts">Unreal Documentation</a> a BuildGraph script file is typically made up of the following elements:</p>
<ul>
<li><strong>Tasks:</strong> Actions that are executed as part of a build process (compiling, cooking, etc.).</li>
<li><strong>Nodes:</strong> A named sequence of ordered tasks that are executed to produce outputs. Before they can be executed, nodes may depend on other nodes executing their tasks first.</li>
<li><strong>Agents:</strong> A group of nodes that are executed on the same machine (if running as part of a build system). Agents have no effect when building locally.</li>
<li><strong>Triggers:</strong> Container for groups that should only be executed after manual intervention.</li>
<li><strong>Aggregates:</strong> Groups of nodes and named outputs that can be referred to with a single name.</li>
</ul>
<h2 id="buildgraph-usage-example">BuildGraph Usage Example</h2>
<p>BuildGraph isn’t just made for building the engine as a whole either, you can compile your game project, compile a specific engine component and even perform batch tasks like file renaming or moving of content.</p>
<p>Here is an example of a BuildGraph script that compiles the UnrealHeaderTool and outputs the files that are compiled:</p>
<div class="language-xml highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="cp"><?xml version='1.0' ?></span>
<span class="nt"><BuildGraph</span> <span class="na">xmlns=</span><span class="s">"https://www.epicgames.com/BuildGraph"</span> <span class="na">xmlns:xsi=</span><span class="s">"https://www.w3.org/2001/XMLSchema-instance"</span> <span class="na">xsi:schemaLocation=</span><span class="s">"https://www.epicgames.com/BuildGraph ../Schema.xsd"</span> <span class="nt">></span>
<span class="nt"><Agent</span> <span class="na">Name=</span><span class="s">"Properties Agent"</span> <span class="na">Type=</span><span class="s">"CompileWin64"</span><span class="nt">></span>
<span class="c"><!-- Compile UnrealHeaderTool --></span>
<span class="nt"><Node</span> <span class="na">Name=</span><span class="s">"Compile UnrealHeaderTool"</span><span class="nt">></span>
<span class="nt"><Compile</span> <span class="na">Target=</span><span class="s">"UnrealHeaderTool"</span> <span class="na">Platform=</span><span class="s">"Win64"</span> <span class="na">Configuration=</span><span class="s">"Development"</span> <span class="na">Tag=</span><span class="s">"#UHTFiles"</span><span class="nt">/></span>
<span class="nt"><Log</span> <span class="na">Message=</span><span class="s">"The following files are part of UnrealHeaderTool:"</span> <span class="na">Files=</span><span class="s">"#UHTFiles"</span><span class="nt">/></span>
<span class="nt"></Node></span>
<span class="nt"></Agent></span>
<span class="nt"><Aggregate</span> <span class="na">Name=</span><span class="s">"Building Examples"</span> <span class="na">Requires=</span><span class="s">"Compile UnrealHeaderTool"</span><span class="nt">/></span>
<span class="nt"></BuildGraph></span>
</code></pre></div></div>
<h3 id="breaking-it-down">Breaking it down</h3>
<p>The BuildGraph xml declaration at the top describes what these nodes mean to the xml parser. One thing to note here is the schema location value needs to point to the location of the schema file in your engine directory <em>(Typically found in <code class="language-plaintext highlighter-rouge">Engine\Build\Graph</code> ).</em></p>
<div class="language-xml highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="cp"><?xml version='1.0' ?></span>
<span class="nt"><BuildGraph</span> <span class="na">xmlns=</span><span class="s">"https://www.epicgames.com/BuildGraph"</span> <span class="na">xmlns:xsi=</span><span class="s">"https://www.w3.org/2001/XMLSchema-instance"</span> <span class="na">xsi:schemaLocation=</span><span class="s">"https://www.epicgames.com/BuildGraph ../Schema.xsd"</span> <span class="nt">></span>
</code></pre></div></div>
<p>The next line as outlined in element section is declaring an agent for a build machine to use, if you are using BuildGraph only on a local build machine this won’t mean anything for you.</p>
<div class="language-xml highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt"><Agent</span> <span class="na">Name=</span><span class="s">"Properties Agent"</span> <span class="na">Type=</span><span class="s">"CompileWin64"</span><span class="nt">></span>
</code></pre></div></div>
<p>The following section of the script defines a <em>node</em> (task to complete) and what it wants that node to do. In this case it wants to build the <a href="https://docs.unrealengine.com/latest/INT/Programming/UnrealBuildSystem/">UnrealHeaderTool</a> for 64bit Windows in Development Configuration and during this process output all the compiled file names to the console.</p>
<div class="language-xml highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt"><Node</span> <span class="na">Name=</span><span class="s">"Compile UnrealHeaderTool"</span><span class="nt">></span>
<span class="nt"><Compile</span> <span class="na">Target=</span><span class="s">"UnrealHeaderTool"</span> <span class="na">Platform=</span><span class="s">"Win64"</span> <span class="na">Configuration=</span><span class="s">"Development"</span> <span class="na">Tag=</span><span class="s">"#UHTFiles"</span><span class="nt">/></span>
<span class="nt"><Log</span> <span class="na">Message=</span><span class="s">"The following files are part of UnrealHeaderTool:"</span> <span class="na">Files=</span><span class="s">"#UHTFiles"</span><span class="nt">/></span>
<span class="nt"></Node></span>
</code></pre></div></div>
<p>Lastly the <em>aggregate</em> specifier is used to allow for the term <em>Building Examples</em> to be used as an alias for running the compile UnrealHeaderTool node. If this file had multiple nodes the <em>aggregate</em> specifier could be used to run only a small selection of those nodes without having to explicitly declare them when running a script.</p>
<div class="language-xml highlighter-rouge"><div class="highlight"><pre class="highlight"><code> <span class="nt"><Aggregate</span> <span class="na">Name=</span><span class="s">"Building Examples"</span> <span class="na">Requires=</span><span class="s">"Compile UnrealHeaderTool"</span><span class="nt">/></span>
</code></pre></div></div>
<h2 id="buildgraph-parameters">BuildGraph Parameters</h2>
<p>The next step, obviously, is to customize our BuildGraph so we can pass in parameters at run time to change the flow of the build. This is quite a simple task and can be achieved with a few simple lines.</p>
<p>Take this BuildGraph script:</p>
<div class="language-xml highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="cp"><?xml version='1.0' ?></span>
<span class="nt"><BuildGraph</span> <span class="na">xmlns=</span><span class="s">"https://www.epicgames.com/BuildGraph"</span> <span class="na">xmlns:xsi=</span><span class="s">"https://www.w3.org/2001/XMLSchema-instance"</span> <span class="na">xsi:schemaLocation=</span><span class="s">"https://www.epicgames.com/BuildGraph ../Schema.xsd"</span> <span class="nt">></span>
<span class="nt"><Agent</span> <span class="na">Name=</span><span class="s">"Agent 1"</span> <span class="na">Type=</span><span class="s">"CompileWin64"</span><span class="nt">></span>
<span class="nt"><Node</span> <span class="na">Name=</span><span class="s">"Manipulate Some Files"</span><span class="nt">></span>
<span class="nt"><Log</span> <span class="na">Message=</span><span class="s">"Here are all the files in Engine/Build/..."</span> <span class="na">Files=</span><span class="s">"Engine/Build/..."</span><span class="nt">/></span>
<span class="nt"><Copy</span> <span class="na">FromDir=</span><span class="s">"Engine/Build"</span> <span class="na">Files=</span><span class="s">"..."</span> <span class="na">ToDir=</span><span class="s">"Engine/TestNumber1"</span><span class="nt">/></span>
<span class="nt"><Delete</span> <span class="na">Files=</span><span class="s">"Engine/TestNumber1/.../*.bat;Engine/TestNumber1/.../*.sh;Engine/TestNumber1/Android/..."</span><span class="nt">/></span>
<span class="nt"><Log</span> <span class="na">Message=</span><span class="s">"Here are all the files in Engine/TestNumber1/..."</span> <span class="na">Files=</span><span class="s">"Engine/TestNumber1/..."</span><span class="nt">/></span>
<span class="nt"></Node></span>
<span class="nt"></Agent></span>
<span class="nt"></BuildGraph></span>
</code></pre></div></div>
<h6 id="taken-from-the-tagsandfiles-build-script-in-the-examples-folder"><em>Taken from the TagsAndFiles build script in the examples folder</em></h6>
<p>In this script we are copying all the files from the <code class="language-plaintext highlighter-rouge">Engine/Build</code> folder to the <code class="language-plaintext highlighter-rouge">Engine/TestNumber1</code> folder, after that we are then deleting all batch files and all the contents in the Android folder.</p>
<p>Let’s say we didn’t want to always delete the files, but instead give our selves and option to do so whenever we wanted.</p>
<p>At the top of the BuildGraph script lets declare a parameter also known as an <em>option</em> :</p>
<div class="language-xml highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt"><Option</span> <span class="na">Name=</span><span class="s">"DeleteAfterCopy"</span> <span class="na">Restrict=</span><span class="s">"true|false"</span> <span class="na">DefaultValue=</span><span class="s">"false"</span> <span class="na">Description=</span><span class="s">"Whether or not we want to delete the Android folders and batch files after copying"</span><span class="nt">/></span>
</code></pre></div></div>
<p>Here we used the <em>Option</em> specifier to denote that this value is an optional parameter and then we gave it a name. The <em>Restrict</em> attribute does what the name implies and restricts this options values to either be true or false. As with the previous attribute <em>DefaultValue</em> is pretty obvious in that it sets the default value of this option.</p>
<p>Using the option value in our script is fairly straight forward:</p>
<div class="language-xml highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c"><!-- Accessing a value in BuildGraph scripts is done by using $([OptionName]) --></span>
<span class="c"><!-- Comparison operations are done the usual way $([OptionName]) == comparator --></span>
<span class="nt"><Do</span> <span class="na">If=</span><span class="s">"'$(DeleteAfterCopy)' == true"</span><span class="nt">></span>
<span class="nt"><Delete</span> <span class="na">Files=</span><span class="s">"Engine/TestNumber1/.../*.bat;Engine/TestNumber1/.../*.sh;Engine/TestNumber1/Android/..."</span><span class="nt">/></span>
<span class="nt"></Do></span>
</code></pre></div></div>
<p>This will now only run when <em>DeleteAfterCopy</em> is set to true.</p>
<p>Your final BuildGraph Script should look something like this:</p>
<div class="language-xml highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="cp"><?xml version='1.0' ?></span>
<span class="nt"><BuildGraph</span> <span class="na">xmlns=</span><span class="s">"https://www.epicgames.com/BuildGraph"</span> <span class="na">xmlns:xsi=</span><span class="s">"https://www.w3.org/2001/XMLSchema-instance"</span> <span class="na">xsi:schemaLocation=</span><span class="s">"https://www.epicgames.com/BuildGraph ../Schema.xsd"</span> <span class="nt">></span>
<span class="nt"><Option</span> <span class="na">Name=</span><span class="s">"DeleteAfterCopy"</span> <span class="na">Restrict=</span><span class="s">"true|false"</span> <span class="na">DefaultValue=</span><span class="s">"false"</span> <span class="na">Description=</span><span class="s">"Whether or not we want to delete the Android folders and batch files after copying"</span><span class="nt">/></span>
<span class="nt"><Agent</span> <span class="na">Name=</span><span class="s">"Agent 1"</span> <span class="na">Type=</span><span class="s">"CompileWin64"</span><span class="nt">></span>
<span class="nt"><Node</span> <span class="na">Name=</span><span class="s">"Manipulate Some Files"</span><span class="nt">></span>
<span class="nt"><Log</span> <span class="na">Message=</span><span class="s">"Here are all the files in Engine/Build/..."</span> <span class="na">Files=</span><span class="s">"Engine/Build/..."</span><span class="nt">/></span>
<span class="nt"><Copy</span> <span class="na">FromDir=</span><span class="s">"Engine/Build"</span> <span class="na">Files=</span><span class="s">"..."</span> <span class="na">ToDir=</span><span class="s">"Engine/TestNumber1"</span><span class="nt">/></span>
<span class="nt"><Do</span> <span class="na">If=</span><span class="s">"'$(DeleteAfterCopy)' == true"</span><span class="nt">></span>
<span class="nt"><Delete</span> <span class="na">Files=</span><span class="s">"Engine/TestNumber1/.../*.bat;Engine/TestNumber1/.../*.sh;Engine/TestNumber1/Android/..."</span><span class="nt">/></span>
<span class="nt"></Do></span>
<span class="nt"><Log</span> <span class="na">Message=</span><span class="s">"Here are all the files in Engine/TestNumber1/..."</span> <span class="na">Files=</span><span class="s">"Engine/TestNumber1/..."</span><span class="nt">/></span>
<span class="nt"></Node></span>
<span class="nt"></Agent></span>
<span class="nt"></BuildGraph></span>
</code></pre></div></div>
<p>Now that we know how to create a BuildGraph script lets try running the scripts we have made.</p>
<h2 id="using-buildgraph-scripts">Using BuildGraph Scripts</h2>
<h4 id="initial-setup">Initial Setup</h4>
<p>To get started running your own build scripts you need to make sure you have cloned/downloaded the source version of the engine found here: <a href="https://github.com/EpicGames/UnrealEngine/">https://github.com/EpicGames/UnrealEngine/</a> (if you get an access denied error make sure you are logged in and have your github account tied to your Epic Games Account).</p>
<p>After downloading the source version Run <em>Setup.bat</em> found in the root directory of the download, following the completion of that script run <em>GenerateProjectFiles.bat</em>. <em>Note: You do <strong>not</strong> need to build the engine to use the BuildGraph command</em>.</p>
<h4 id="running-a-buildgraph-script">Running a BuildGraph Script</h4>
<p>Running a BuildGraph script is as simple as opening up a cmd window and running a single line of code. All it needs to do is call the UnrealAutomationTool and execute the BuildGraph command. To run our specific scripts we give it the path to the script we want to run and pass it the node we want to execute.</p>
<div class="language-sh highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="s2">"[EnginePath]</span><span class="se">\E</span><span class="s2">ngine</span><span class="se">\E</span><span class="s2">ngine</span><span class="se">\B</span><span class="s2">uild</span><span class="se">\B</span><span class="s2">atchFiles</span><span class="se">\R</span><span class="s2">unUAT.bat"</span> BuildGraph
<span class="nt">-Script</span><span class="o">=[</span>Path To Your Script Location e.g Engine/Build/Graph/Examples/AllExamples.xml]
<span class="nt">-target</span><span class="o">=[</span>Name of node to run]
</code></pre></div></div>
<p>The <a href="#BuildGraph-Usage-Example">original example</a> I gave is found in <code class="language-plaintext highlighter-rouge">Engine\Engine\Build\Graph\Examples </code> folder and is called <code class="language-plaintext highlighter-rouge">Building.xml</code>. To run this BuildGraph script all we would need to do is open up a cmd window and run:</p>
<div class="language-sh highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="s2">"[EnginePath]</span><span class="se">\E</span><span class="s2">ngine</span><span class="se">\E</span><span class="s2">ngine</span><span class="se">\B</span><span class="s2">uild</span><span class="se">\B</span><span class="s2">atchFiles</span><span class="se">\R</span><span class="s2">unUAT.bat"</span> BuildGraph
<span class="nt">-Script</span><span class="o">=</span><span class="s2">"Engine</span><span class="se">\E</span><span class="s2">ngine</span><span class="se">\B</span><span class="s2">uild</span><span class="se">\G</span><span class="s2">raph</span><span class="se">\E</span><span class="s2">xamples</span><span class="se">\B</span><span class="s2">uilding.xml"</span>
<span class="nt">-target</span><span class="o">=</span><span class="s2">"Compile UnrealHeaderTool"</span>
</code></pre></div></div>
<h4 id="running-with-options">Running with options</h4>
<p>Using the script we made in the <a href="#buildgraph-parameters">Parameters Section</a> we can do the same thing we did above. We call the <em>RunUAT</em> batch file, give it a script location, and a target node to execute. This time however we set the value of <em>DeleteAfterCopy</em>:</p>
<div class="language-sh highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="s2">"[EnginePath]</span><span class="se">\E</span><span class="s2">ngine</span><span class="se">\E</span><span class="s2">ngine</span><span class="se">\B</span><span class="s2">uild</span><span class="se">\B</span><span class="s2">atchFiles</span><span class="se">\R</span><span class="s2">unUAT.bat"</span> BuildGraph
<span class="nt">-Script</span><span class="o">=</span><span class="s2">"Engine</span><span class="se">\E</span><span class="s2">ngine</span><span class="se">\B</span><span class="s2">uild</span><span class="se">\G</span><span class="s2">raph</span><span class="se">\E</span><span class="s2">xamples</span><span class="se">\T</span><span class="s2">utorialBuild.xml"</span>
<span class="nt">-target</span><span class="o">=</span><span class="s2">"Compile UnrealHeaderTool"</span> <span class="nt">-set</span>:DeleteAfterCopy<span class="o">=</span><span class="nb">true</span>
</code></pre></div></div>
<p>As you can see setting options is done using <code class="language-plaintext highlighter-rouge">-set:[Option Name]=[Value]</code>. As we set the required attribute earlier if we try and enter a value that is not true or false the build will fail. If all went well you should now have a new folder called <strong>TestNumber1</strong> in your Engine folder that is missing all the batch files and the Android folder.</p>
<p>If you want some more examples of how to use the BuildGraph system I do recommend checking out the examples folder I mentioned above as well as the BuildGraph script used to compile the engine (Which you can find more about in my article on <a href="/buildgraph/2017/02/06/Building-an-installed-ue4-from-source/">Building an Installed Version of Unreal</a>).</p>
<p>If you have any questions or problems with anything you find in this article please do let me know either in the comment section below or you can hit me up on twitter: <a href="https://twitter.com/jack_knobel">jack_knobel</a>.</p>
<h1 id="useful-links">Useful Links</h1>
<ul>
<li><a href="https://forums.unrealengine.com/showthread.php?125033-How-to-create-Rocket-build-that-can-deploy-Dedicated-Server-of-game&p=645258#post645258">Distributed Build with Dedicated Server target</a></li>
<li><a href="https://forums.unrealengine.com/showthread.php?123490-Current-advice-for-distributing-custom-engine-builds-to-team-without-recompiling">Distributing Custom Engine Build</a></li>
<li><a href="https://docs.unrealengine.com/latest/INT/Programming/Development/BuildGraph/Usage/index.html">Build Graph Usage</a></li>
<li><a href="https://de45xmedrsdbp.cloudfront.net/Resources/files/BuildTools-2031748007.pdf">Unreal Build Tool Presentation (PDF)</a></li>
</ul>Jack KnobelWhat is BuildGraph?