Setting Up Perforce for Unreal

This post describes set up of a Perforce HelixCore server for a game studio using the Unreal Engine.

Portions of this post may drip with enthusiasm for one or more services. I can’t help that marketing practices have coopted all forms of sincere speech, and now anyone with something positive to say sounds like a pathetic shill. None of it is an endorsement.

0. Intro

With Unreal Engine, I prefer Perforce for source control—its integration with the UE editor is best in class; it’s the system used at Epic, and Unreal Game Sync currently requires it. Managed SaaS offerings are convenient and robust, but costly, so I prefer to run and manage deployments myself. That said, it’s not the simplest thing. I’ve set up dozens of Perforce servers, local machines, intranet and internet servers, VMs, Docker containers, and across multiple OSes—Linux, Windows, and Mac. I’m sure I do it wrong, because I don’t actually like doing it. But a) hate recurring costs, and b) I will never develop software without source control because that’s dumb.

My process goes something like:

  1. Plan deployment
  2. Set up environment
  3. Install application
  4. Basic configuration
  5. Set up a typemap
  6. Connect with P4Admin
  7. Add a Standard User
  8. Create a Stream Depot
  9. Connect with P4V, Create Stream and Workspace
  10. Readme.md
  11. Set up .p4ignore
  12. Take Nap

1. Plan Deployment

Have considered:

  • Personal machine—hardware is cheap, IT is hard, scaling is hard
  • *Virtual private server—costs scale with needs, IT is hard, redundancy & security is easier
  • Virtual machine—at home or datacenter, IT is even more complex, migration/scaling is easier
  • **Docker container—migration is even easier, IT is batshit
  • Managed cloud services—hands-off system administration is easy peasy, pricey AF

*the option I am picking
**if I fully grokked Docker, I’d do this; I’ve run it before, but it remains one extra layer of comfort that I don’t want to manage during crisis

One of the best deals in low-end hosting of Virtual Private Servers I found was Hostinger. A Tier 2 VPS runs $7/month for two years, renewing at $11/mo. Automated backups and easy snapshotting take care of elementary disaster preparedness.

2. Set Up Environment

After some prototyping—a little trial and error—I found Ubuntu 22.04 setup to be the most straightforward. Package management, configuration, and patching experiences succeeded without error or workaround.

Keep in mind, this approach is lazy! I first create the server using password-only authentication. After everything is set up and working, I go back to enable SSH key auth. It’s not the most secure approach, but I don’t like generating keys until I know I only have to do it once.

This will do the first pass of updating, upgrading, and service restarting. When completed, I exit the SSH session. Using the Hostinger web-based server control panel, I restart the server. It’s arguably unnecessary, but a nice sanity check that I haven’t already screwed something up and the machine will boot.

3. Install Application

Once I’m reconnected to the server, I begin the Perforce installation.

That’ll finish silently. Then:

Looks good.

Packages will be fetched, package lists read, a dependency tree built, and state information read. Lastly, I see:

I’ll get to that, but first, Perforce.

More package work as apt gets and installs Perforce HelixCore. But, before it continues, I’m asked:

It concludes with the following message:

Now I check for those upgradeable packages mentioned before:

Still just the two, so I upgrade the one with a dependency, and both are upgraded.

Once again I am warned:

And confirm:

This ends with:

4. Basic Configuration

Now I’ll run the initial configuration script.

5. Set Up a Typemap

A typemap is a set of rules to help Perforce know how best to handle a given type of file. It tells perforce how to store and lock files based on their filename extensions. The following command will effectively open the typemap in the system’s text editor and, upon saving, update configuration.

This command will open the typemap file in VIM if the OS is Ubuntu. Press [i] to enter “insert” mode to begin editing. The following example typemap merges suggestions from Epic with the default created by Perforce, or I could copy another, such as John Scotts’ (GitHub).

ESC returns VIM to Command Mode.

VIM saves (write) and exits (quit). Then I do one more probably unnecessary server restart, and create the server’s first snapshot to capture this moment, before I potential mess something up.

6. Connect With P4Admin

On my client machine, I have P4V and P4Admin installed. I launch P4Admin to test the connection and continue configuration. Add the IP address of your server (“ssl:###.###.###.###:1666”), and the name of your Perforce superuser, you’ll be prompted for the password during the connection attempt.

7. Add Standard User

I don’t work in Perforce with the superuser account, instead creating a new standard user for myself to work from. Select the Users & Groups tab and Ctrl+N, or R-click in the user list and select New User… or click the Add User button in the button bar (so many choices!).

8. Create a Stream Depot

With the Depots tab selected, Ctrl+N to create a new depot.

  • Depot name according to game
  • Depot type: stream
  • Stream Depth: 2

A stream depth of 2 allows for a straightforward [Category] / [Name] branch organization. Any higher and it’s Annoying City.

Then, in the Depots tab, for clarity’s sake, I delete the default depot through the right click menu.

9. Connect with P4V, Create Stream and Workspace

Launch P4V and connect to the server with your standard user account, and without specifying a workspace. Then use View > Streams to open the Streams tab, and create a new stream with Ctrl+N, or r-click menu and select New Stream.

  1. Stream name: main/main
  2. Stream type: mainline
  3. Uncheck ” Create a workspace to use with this stream”
  4. Uncheck “Populate the mainline stream after it is created”
  5. Click [OK]

Now I get a workspace created.

  1. In the Streams list, I right-click on “main/main” and select New Workspace…
  2. Select the stream (main/main) and right-click, New Workspace…
  3. Workspace name something like “username_descriptive”
  4. Workspace root I point at a directory on a large “data” drive where I keep a general “Depot” parent directory
  5. Leave Switch to new workspace immediately

On my local machine I make a starter readme.md and save it in the workspace root folder (d:\Depots\user_workspacename\).

Perforce Streams: Everything You Need to Know (YouTube)
Perforce Helix Core Beginner’s Guide: How to Create a Workspace (YouTube)

10. readme.md

On my local machine I make a starter readme.md and save it in the workspace root folder (d:\Depots\user_workspacename\). Then, back in P4V, refresh the workspace view and find the file, select and add to add it to a new changelist, and submit it right away.

11. Set up .p4ignore

Once I have successfully submitted a readme, things are looking good. So my next and last step in this initial setup is getting a .p4ignore working. This one is copied from Matt Marcin’s (GitHub).

I save this as a “.p4ignore” next to the readme. Let’s say D:\Depots\user_gameworkspace\. Then I set P4 to look for ignore files.

Then I check to see…

If it works (returning a list of ignored files) I mark the .p4ignore for add, and then submit.

If you need to know more about ignores: How to Ignore Files and Directories in Perforce Helix Core (YouTube)

12. Take Nap

At this point, my brain is ready for a break. I create another server snapshot before taking a nap. When I come back, I’ll set up a standard Linux user account, set the server up SSH key authentication, and start clamping down the firewall.

I believe in you!
—Isaac

Comments

One response to “Setting Up Perforce for Unreal”

  1. […] Setting up a Perforce Server for Unreal […]