<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Andreas Andersson</title>
    <description>The latest articles on DEV Community by Andreas Andersson (@derwiath).</description>
    <link>https://dev.to/derwiath</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F813298%2F4d0a24e8-92ff-4467-8a62-7f32e31f13d9.jpeg</url>
      <title>DEV Community: Andreas Andersson</title>
      <link>https://dev.to/derwiath</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/derwiath"/>
    <language>en</language>
    <item>
      <title>Working with Unreal Engine source releases in Plastic SCM</title>
      <dc:creator>Andreas Andersson</dc:creator>
      <pubDate>Thu, 31 Mar 2022 08:27:27 +0000</pubDate>
      <link>https://dev.to/goals/working-with-unreal-engine-source-releases-in-plastic-scm-ihf</link>
      <guid>https://dev.to/goals/working-with-unreal-engine-source-releases-in-plastic-scm-ihf</guid>
      <description>&lt;p&gt;&lt;strong&gt;This guide is for &lt;a href="https://www.plasticscm.com" rel="noopener noreferrer"&gt;Plastic SCM&lt;/a&gt; users, that want to build a game using &lt;a href="https://www.unrealengine.com" rel="noopener noreferrer"&gt;Unreal Engine&lt;/a&gt;, and plan to compile and make changes to the engine code itself, while also upgrading engine releases as they are released by Epic.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Hi, I'm Andreas, a game developer here at GOALS. We are building a football game using Unreal Engine and use Plastic to manage our source code and assets. This article tells the story on how we bridged the gap between Git and Plastic to stay on top of new engine releases.&lt;/p&gt;

&lt;h2&gt;
  
  
  Building blocks
&lt;/h2&gt;

&lt;p&gt;Full engine source code is served via &lt;a href="https://github.com/EpicGames/UnrealEngine" rel="noopener noreferrer"&gt;Unreal Engine own GitHub repository&lt;/a&gt;, to which you get access by registering your GitHub user with Epic. See &lt;a href="https://www.unrealengine.com/en-US/ue4-on-github" rel="noopener noreferrer"&gt;How do I access Unreal Engine 4 C++ source code via GitHub?&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Each official engine release is labelled with a Git tag, for example &lt;a href="https://github.com/EpicGames/UnrealEngine/releases/tag/4.27.2-release" rel="noopener noreferrer"&gt;4.27.2-release&lt;/a&gt; or &lt;a href="https://github.com/EpicGames/UnrealEngine/releases/tag/5.0.0-preview-2" rel="noopener noreferrer"&gt;5.0.0-preview-2&lt;/a&gt;. Here you also find a downloadable tarball or zip for the release.&lt;/p&gt;

&lt;p&gt;Then we have a Plastic repository, where we want to develop our game.&lt;/p&gt;

&lt;h2&gt;
  
  
  The idea
&lt;/h2&gt;

&lt;p&gt;The main idea is to see Unreal Engine as a third-party vendor library, albeit a really big one. One strategy for vendor libs is to keep a clean and unmodified copy of it in a separate branch, that is then merged into your development branch.&lt;/p&gt;

&lt;p&gt;This idea isn't new, it's basically exactly what &lt;em&gt;Karl Fogel&lt;/em&gt; describe in &lt;a href="https://durak.org/sean/pubs/software/cvsbook/Tracking-Third_002dParty-Sources-_0028Vendor-Branches_0029.html" rel="noopener noreferrer"&gt;Tracking Third-Party Sources (Vendor Branches)&lt;/a&gt;, a section of his 20+ years old book titled &lt;em&gt;Open Source Development With CVS&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Sounds simple enough, but how do we apply it to Plastic and Unreal Engine?&lt;/p&gt;

&lt;h2&gt;
  
  
  Branch layout and upgrade flow
&lt;/h2&gt;

&lt;p&gt;Let us start with deciding a branch layout. The game itself is developed on &lt;code&gt;main&lt;/code&gt;, we keep unmodified Unreal Engine releases in &lt;code&gt;vendor-unreal-engine&lt;/code&gt; that is &lt;strong&gt;merged&lt;/strong&gt; down to main for each release.&lt;/p&gt;

&lt;p&gt;Take this example, where we set up an empty repo with &lt;code&gt;4.27.0&lt;/code&gt; that we upgrade to &lt;code&gt;4.27.1&lt;/code&gt; and finally &lt;code&gt;4.27.2&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Faxykfp32rpbmkj5lx5ps.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Faxykfp32rpbmkj5lx5ps.png" alt="Branch Layout"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This image speaks a thousand words, in text it says:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Start with an empty Plastic repo&lt;/li&gt;
&lt;li&gt;Add &lt;code&gt;4.27.0&lt;/code&gt; to &lt;code&gt;vendor-unreal-engine&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Make a small tweak to the engine itself.&lt;/li&gt;
&lt;li&gt;Merge it all down into &lt;code&gt;main&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Add your games main module&lt;/li&gt;
&lt;li&gt;Upgrade &lt;code&gt;vendor-unreal-engine&lt;/code&gt; with release &lt;code&gt;4.27.1&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Merge the new release with &lt;code&gt;main&lt;/code&gt;, and apply fixes
to make your game module compile and work again.&lt;/li&gt;
&lt;li&gt;Merge the new engine into &lt;code&gt;main&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Make local modification to the engine itself&lt;/li&gt;
&lt;li&gt;Upgrade &lt;code&gt;vendor-unreal-engine&lt;/code&gt; with release &lt;code&gt;4.27.2&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Merge it with &lt;code&gt;main&lt;/code&gt;, and apply even more fixes
to your game so that it still works.&lt;/li&gt;
&lt;li&gt;Publish the new release to &lt;code&gt;main&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;And continue making local changes to the engine&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Importing Unreal Engine releases
&lt;/h2&gt;

&lt;p&gt;So, how do you import or upgrade the engine source code into our &lt;code&gt;vendor-unreal-engine&lt;/code&gt;?&lt;/p&gt;

&lt;h3&gt;
  
  
  Import by delete and re-adding all files
&lt;/h3&gt;

&lt;p&gt;One crude strategy is to delete all files on the vendor branch and simply copy all files from the new release, and then let Plastic detect which files have been added, removed, modified or moved.&lt;/p&gt;

&lt;p&gt;This should work well. Alas, plastics move detection seem to miss most moves, maybe there are too many files involved in engine upgrades for it to be practically possible? It would be understandable, upgrading &lt;code&gt;4.27.2&lt;/code&gt; to &lt;code&gt;5.0.0-early-access-1&lt;/code&gt; modifies over 50k files.&lt;/p&gt;

&lt;p&gt;As a result, moved files will be imported as a delete followed by an add.&lt;br&gt;
If you have made changes to the file in the old location on your &lt;code&gt;main&lt;/code&gt;-branch, Plastic will not help you merge these changes into the file in its new location. Instead, it will ask you how to resolve your changes to the old, deleted file. Forcing you to manually copy your changes into the new location.&lt;/p&gt;

&lt;p&gt;Depending on how widespread your local engine changes are, this strategy might be good enough, for us at GOALS it was not.&lt;/p&gt;
&lt;h3&gt;
  
  
  Import by replicating changes from Git
&lt;/h3&gt;

&lt;p&gt;Luckily, we can do better. Full revision history is available in the main Git repo, it knows which files has been modified, added or removed, and most importantly it also knows which files have been renamed or moved.&lt;/p&gt;

&lt;p&gt;The command we use is &lt;code&gt;git diff --name-status&lt;/code&gt;, here's the output of the diff between &lt;code&gt;4.27.1&lt;/code&gt; and &lt;code&gt;4.27.2&lt;/code&gt;. Note that this is just an excerpt, the real diff contains roughly 460 changes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git diff &lt;span class="nt"&gt;--name-status&lt;/span&gt; 4.27.1-release 4.27.2-release
M   Engine/Build/Build.version
A   Engine/Extras/Containers/Dockerfiles/linux/dev-slim/Dockerfile
D   Engine/Source/Programs/Enterprise/Datasmith/DatasmithSolidworksExporter/Private/Animations/AnimationExtractor.cs
R064    Samples/PixelStreaming/WebServers/SignallingWebServer/platform_scripts/cmd/run.bat  Samples/PixelStreaming/WebServers/SignallingWebServer/platform_scripts/cmd/run_local.bat
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The leading column means:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;M&lt;/code&gt; - File was modified in place&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;A&lt;/code&gt; - File was added&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;D&lt;/code&gt; - File was deleted&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;R*&lt;/code&gt; - File was renamed or moved.
The number is a percentage of how certain Git is that the file was in fact moved, and not a delete followed by an add. There is some grey area when it comes to moves in Git, sometimes a file is moved, but then modified to fit in its new location. For example, a moved C++ file may need to have include paths tweaked to compile.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Git uses some fuzzy heuristics to discern moves from adds and deletes. Most of the time it seems to make good guesses. When it fails it is not a big deal; the old location will still be deleted, and the name, location and content of the added file will be correct.&lt;/p&gt;

&lt;p&gt;Now, it's just a matter of replicating these changes in &lt;code&gt;vendor-unreal-engine&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Dealing with modified files is simple, just check out in Plastic and copy the file from the new release.&lt;/p&gt;

&lt;p&gt;Adding files is almost as easy, just copy their content. But, if the target folder does not exist in Plastic we need to first create and add it before coping the file.&lt;/p&gt;

&lt;p&gt;For deletes, the opposite of adds, we start by deleting the file itself.&lt;br&gt;
If the folder in which it existed became empty, we need to remove the folder, we also need to iterate up the hierarchy to delete any now empty parent directories.&lt;/p&gt;

&lt;p&gt;For moves we start by creating and adding target directories to before we tell Plastic to move the file. Finally, we copy the contents of the file from the new release.&lt;/p&gt;

&lt;h3&gt;
  
  
  Announcing ueimporter
&lt;/h3&gt;

&lt;p&gt;This git-&amp;gt;plastic import process is very scriptable, and I wrote a command line tool called &lt;code&gt;ueimporter&lt;/code&gt; that takes care of it all. I'm happy to announce that GOALS are now open-sourcing this tool, available in GitHub at &lt;a href="https://github.com/goalsgame/ueimporter" rel="noopener noreferrer"&gt;goalsgame/ueimporter&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Ignoring the elephant in the room
&lt;/h2&gt;

&lt;p&gt;If you have ever tried to store Unreal Engine source inside Plastic, you may have noticed a rather big elephant that I so far avoided; Plastics ignore file, and it's incompatibility with Gits equivalent.&lt;/p&gt;

&lt;p&gt;Unreal Engines GitHub repo comes with a rather complex &lt;code&gt;.gitignore&lt;/code&gt; file. Whenever you build or work with the engine various intermediate and temporary files is scattered all over your workspace, not to mention the thousands of files that is downloaded when you run &lt;code&gt;Setup.bat|sh&lt;/code&gt;.&lt;br&gt;
These files should not be committed into Git, and likewise we do not want them checked into Plastic.&lt;/p&gt;

&lt;p&gt;It is not possible to directly translate Gits &lt;code&gt;.gitignore&lt;/code&gt; file into Plastics &lt;code&gt;ignore.conf&lt;/code&gt;, the two systems have rather different rules deciding in what order ignore patterns are applied.&lt;/p&gt;

&lt;h3&gt;
  
  
  Ignoring in Git
&lt;/h3&gt;

&lt;p&gt;On one hand, we have Git, where each line specifies a file or directory pattern, any subsequent matching line will override preceding matches. A simple philosophy that is relatively easy to understand.&lt;/p&gt;

&lt;p&gt;If we compress Unreals &lt;code&gt;.gitignore&lt;/code&gt; into a nutshell, it can be described like this:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Start by ignoring &lt;strong&gt;all&lt;/strong&gt; files&lt;/li&gt;
&lt;li&gt;Add exceptions to &lt;strong&gt;not ignore&lt;/strong&gt; certain extensions.
For instance, &lt;code&gt;.h&lt;/code&gt; and &lt;code&gt;.cpp&lt;/code&gt; files.&lt;/li&gt;
&lt;li&gt;Add exceptions to those exceptions so that temporary build folders are ignored.
For example, everything under &lt;code&gt;Engine/Intermediate&lt;/code&gt; should be ignored, or else the &lt;code&gt;*.h&lt;/code&gt; and &lt;code&gt;*.cpp&lt;/code&gt; files that &lt;code&gt;UnrealHeaderTool&lt;/code&gt; generates during the build process would be tracked.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;On and on the list goes, with more detailed exceptions and ignore patterns. There are close to 160 rules listed in the ignore file for the &lt;code&gt;5.0.0-preview-2&lt;/code&gt; release.&lt;/p&gt;

&lt;h3&gt;
  
  
  Ignorance is not a bliss in Plastic
&lt;/h3&gt;

&lt;p&gt;Then we have Plastic, it prioritizes patterns based on its type, rather than in what order it occur in its &lt;code&gt;ignore.conf&lt;/code&gt;. Two patterns of the same type are applied in the order they appear in the file. Exception patterns take precedence over ignore patterns of the same type.&lt;/p&gt;

&lt;p&gt;So what pattern types are we talking about? Quoting the &lt;a href="https://www.plasticscm.com/book/#_pattern_files" rel="noopener noreferrer"&gt;Pattern evaluation hierarchy&lt;/a&gt; section of the &lt;em&gt;Version Control, DevOps and Agile Development with Plastic SCM&lt;/em&gt; book.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Plastic SCM will try to match the path of an item using the patterns in the file in a predefined way.&lt;br&gt;
This means that some pattern formats take precedence over others rather than processing the patterns&lt;br&gt;
in the order they appear in the file.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Absolute path rules that match exactly&lt;/li&gt;
&lt;li&gt;Catch-all rules&lt;/li&gt;
&lt;li&gt;Name rules applied to the current item&lt;/li&gt;
&lt;li&gt;Absolute path rules applied to the item directory structure&lt;/li&gt;
&lt;li&gt;Name rules applied to the item directory structure&lt;/li&gt;
&lt;li&gt;Extension rules&lt;/li&gt;
&lt;li&gt;Wildcard and Regular expression rules&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;

&lt;p&gt;There are more devils in the details, but that's the gist of it.&lt;/p&gt;

&lt;p&gt;Unreals &lt;code&gt;.gitignore&lt;/code&gt; use most of these types, but relies on the order to accomplish desired behaviour. Just copy pasting this to &lt;code&gt;ignore.conf&lt;/code&gt; does not work, because it wreaks havoc to this order.&lt;/p&gt;

&lt;h3&gt;
  
  
  An acceptable workaround
&lt;/h3&gt;

&lt;p&gt;We at GOALS have wrestled quite a bit with our &lt;code&gt;ignore.conf&lt;/code&gt;, trying to come up with equivalent behaviour as in Git. So far, we haven't nailed it, but have at least arrived at a config file that we can endure.&lt;/p&gt;

&lt;p&gt;We simply ignore the entire &lt;code&gt;Engine&lt;/code&gt;-folder, that gets rid of most of the intermediate and temporary files that is explicitly ignored in &lt;code&gt;.gitignore&lt;/code&gt;.&lt;br&gt;
The main drawback with this is that we must remember to manually add files to Plastic, whenever we add anything to &lt;code&gt;Engine&lt;/code&gt;, or else it will not show up as a pending change that can be checked in. We can edit files that are already checked into Plastic just fine, they will be detected as changed.&lt;/p&gt;

&lt;p&gt;For our games own modules and plugins it was relatively easy to write ignore rules, mainly because Unreal write most files to &lt;code&gt;Engine&lt;/code&gt; during the setup process and build artefacts all end up in easily identified intermediate folders.&lt;/p&gt;

&lt;h3&gt;
  
  
  Ignore files and our vendor branch
&lt;/h3&gt;

&lt;p&gt;Thankfully, the ignore file is irrelevant on our &lt;code&gt;vendor-unreal-engine&lt;/code&gt; branch.&lt;br&gt;
Here we always want Plastic to detect all files, so that we can check them in and later have them merged into &lt;code&gt;main&lt;/code&gt;. This implies that you must clear out any private files before you start importing a new engine release to the vendor branch. You should not build or do anything to pollute your workspace here, do that on an upgrade branch after merging with main (where an ignore file is present).&lt;/p&gt;

&lt;h2&gt;
  
  
  Parting words
&lt;/h2&gt;

&lt;p&gt;With this setup you have the power to change the engine at will and still stay up to date with new releases. How you wield this power is up to you.&lt;/p&gt;

&lt;p&gt;Consider that any merge conflicts you get with new engine releases, after making local changes, will need to be resolved. This is a manual process that is hard to automate.&lt;/p&gt;

&lt;p&gt;In the past, when working in another big game engine, I have seen many, many, &lt;strong&gt;many&lt;/strong&gt; dev-months been sunk into resolving merge conflicts and follow up issues, due to local modifications when the engine was upgraded. Tears were shed, good night sleeps lost and dev-happiness fled down the drain. It was not pretty.&lt;/p&gt;

&lt;p&gt;Keep your engine changes small and isolated, and tag changed lines with begin/end comments. If a change can be done in your game module or a plug-in that is the preferred way.&lt;/p&gt;

&lt;p&gt;One benefit with this setup, is that you can cherry-pick fixes from Epics mainline and push directly into your own &lt;code&gt;main&lt;/code&gt;. Later, when the fix gets included in an official release your divergence should just resolve itself in the upgrade process.&lt;/p&gt;

&lt;p&gt;Finally, upgrade the engine often, the further you diverge from the mainline the harder it will be to catch up. Take one version at a time, even if you are more than one version behind. In their &lt;a href="https://www.youtube.com/watch?v=AaZrAjkBhlM" rel="noopener noreferrer"&gt;Fish Slapping Dance&lt;/a&gt; Monty Python teach us that it's better to be slapped with a small pilchard multiple times than it is to be slapped by a big fat halibut just once.&lt;/p&gt;

&lt;p&gt;Take care, stay safe and happy game making.&lt;/p&gt;

</description>
      <category>gamedev</category>
      <category>unrealengine</category>
      <category>plasticscm</category>
      <category>git</category>
    </item>
  </channel>
</rss>
