Unity Cloud Build
Tutorial
Beginner
30 Mins
Overview
Summary
By the end of this lesson, you will understand what Unity Cloud Build is and how it works.
Topics we'll cover
Language
English
Recommended Unity Versions
5
Tutorial
Unity Cloud Build
1.
Introduction to Unity Cloud Build
By the end of this lesson, you will understand what Unity Cloud Build is and how it works.

What is Unity Cloud Build?

A service that automates the build pipeline for Unity games.

Why Should I Use Cloud Build?

By using Cloud Build automation services, you will
  • Save Time. Builds are compiled and distributed automatically, minimizing manual work and intervention. Games with multiple platforms can be consolidated into a single build process.
  • Improve Quality. Games are built continuously as changes are detected (“Continuous Integration”), enabling detection of issues as they are introduced to the project.
  • Distribute Faster. Cloud-based infrastructure compiles builds; in parallel if for multi platform projects. Completed builds are available to download by anyone on the team through Cloud Build’s website.

How does Unity Cloud Build work?

Unity Cloud Build monitors your source control repository (e.g. Git, Subversion, Mercurial, Perforce). When a change is detected, a build is automatically generated by Cloud Build. When the build is completed, you and your team are notified via email. Your build is hosted by Unity for you and your team mates. If the build is not successful, you’re also notified and provided with logs to begin troubleshooting.

What do I need to use Unity Cloud Build?

A repository that is source controlled. The following source control management (“SCM)” systems are supporte
  • Git
  • Subversion
  • Mercurial
  • Perforce

How do I create a Source Control Repository?

See Lesson 2: Your First Source Control Repository

2.
Creating Your First Source Control Repository
By the end of this lesson, you will have a local Git repo connected to a remote Git server, with a Unity project in it.
If you already have a repository with source control (Git, Subversion, Perforce, or Mercurial) for your project, or want to use a sample project to test out Unity Cloud Build, you can proceed to Lesson 3: Creating Your First Cloud Build Project.
In this lesson, you will create a repository using the following
  • Bitbucket: A free repository for small projects
  • Git: A popular source control system, integrated with Bitbucket.
  • SourceTree: A user-friendly GUI that works with Git and Bitbucket.
These tools are good for SCM beginners because they enable fast setup and easy use.
To get started, you’ll need an existing Unity project on your local machine. If you do not have one, complete the following project: Space Shooter

1. Download SourceTree

Go to www.sourcetreeapp.com to download and install SourceTree.
 

2. Create a Bitbucket Account

Visit bitbucket.org and sign up for a free Personal Account.
When asked to create your first repository, ‘No thanks’. We will be creating a repository with SourceTree.
 

3. Using SourceTree, create a repository on Bitbucket.

Open SourceTree and enter your Bitbucket login username and password when prompted.
 
After logging in you will be prompted to “Clone” your repo (to “Clone a repo” is to copy all the relevant files from a repository to your local machine). If you have not created a repo associated with your Bitbucket account, the list should be empty. Click “Skip Setup”.
 
After clicking “Skip Setup”, you will see the Repository Browser window.
 
We will create a remote repository using the Bitbucket account you previously created. Click “+ New Repository” in the Repository Browser. You will see a dropdown list. Choose 'Create a remote repository'.
 
You will be prompted with a “Create a remote repository” window.
 
Use the following configuration settings:
  • Account: Bitbucket Account
  • Owner: Bitbucker User name
  • Name: Any
  • Description: Any
  • Type: Git
  • This is a private repository: Checked
Click “Create”
You will be brought back to the “Repository Window”. Click on “Remote” and you should see the name of the repo you just made in the list.
 

4. Clone Your Repo

From the Repository Window | Remote window, click on the Bitbucket repository you created in the previous steps. The following prompt will appear.
 
  • Source URL: Leave as-is, but take note of it, as you will use it later when configuring Unity Cloud Build
  • Destination Path: Choose a location on your local machine where repository files will be stored. Note that the Destination Path must point to a directory that has no items in it.
  • Name: Any
  • Advance Options: Leave as-is
Click “Clone”
After, you will be brought back to the Repository Window | Local, where you will see the local copy of the repository you just created. Note that the repository is empty; you will populate it in the next steps.
 

5. Populate your local repo with your Unity Project

From the Repository Window | Local, double click on your repo. Enter your name and email when prompted.
 
You will now populate your local repository. Find your Local Unity Project and move all files to the repo Destination Path you defined in Step 4. In the following screen shot, the unity project “MyFirstProject” will be moved into the local repository folder “MyFirstUnityRepo”
 
Upon populating your local repo, SourceTree will automatically detect changes and will update, as follows:
 

6. Commit and Push your Local Repo to the Remote Repo

Unity Cloud Build monitors your remote repo. To do so, you must COMMIT and PUSH your files to the remote repo.
Select the “Unstaged files” check box to select all files that will be pushed to the server.
NOTE: You'll notice three dots (•••) to the right of each filename - click these dots to access a 'more' menu. Use this menu to select 'Ignore file' for your Unity ‘Library’ folder (Unity Cloud Build will construct the Library folder during the build process). You can also 'Ignore' any other files that aren't required by Unity to build your project. Not completing this step will make the build process slower that necessary.
Click “Commit” on the top of the screen. Enter your name and email if prompted.
 
Enter in comments and click “Commit”
 
The following should appear: "There is nothing left to commit"
 
Click “Push” to copy all committed files to the Remote Repository.
 
Click “OK”. This will initiate the upload process.

7. Check your remote repo

Go to bitbucket.org and login with your credentials. You should see your repository name listed on the first screen. Click it's name to go to the page about your repo.
Once you're on the repo page, go to the address bar in your browser and copy the url / address you see there.
 
This will be the URL that you give Unity Cloud Build when you add a new project. Click the 'Git' tab on this page, or follow the instructions in the Unity Cloud Build setup wizard to add an SSH key to your Bitbucket account to allow access.

3.
Your First Cloud Build Project
By the end of this lesson, you will have a Unity Cloud Build project that will automatically compile and notify you when you commit to you code repository.
To get started, you’ll need the following.
  1. A source control repository. Unity Cloud Build supports Git, Subversion, Mercurial, and Perforce. See lesson 1.
  2. A Unity Cloud Build account.

1. Create a Project

Go to https://build.cloud.unity3d.com and sign in with your Unity Developer Account. You will be brought to the Cloud Build home page
 
On the Cloud Build home page, click on “Add New”. Cloud Build will ask you to pick a name for your project, as well as the organization it will belong to.
 
  • Organization: Click on the Drop Down menu and select your user name.
  • Project Name: Any

2. Connect your Unity Cloud Build Project to your Remote Repository

  • If you started with Lesson 1: Getting Started with Cloud Build provide the URL from your BitBucket repo.
  • If you did not, use the following sample project: https://github.com/tsugi/exampleunityangrybots
After providing the repo URL, Click Next:
 

3. Configure access rights

If your repo is private Cloud Build will ask you to add an SSH key so that we can access your files and build them (if it is public you will automatically skip to the next step). If you created a BitBucket Repo using the previous lesson, you will need to attach the SSH key provided by Unity Cloud Build to your BitBucket Repo. Not doing this will result in a failed build attempt. Log into Bitbucket and add the Cloud Build SSH key to your Bitbucket account.
If you used the sample project from the previous step, you will not be asked to configure access rights; the project is Public.
 
Copy the SSH key provided by Cloud Build
Associate the SSH key provided by Cloud Build to your repo. If continuing from Lesson 2, you will add the SSH key to your BitBucket repo.
 
When you have finished configuring your repo, click Next to configure settings

4. Configure your Unity Cloud Build project

You’ll be asked to choose a platform. For this lesson, select Web Player.
 
You’ll be asked to provide further configuration details. You will need to select a branch from your repo to build from. If you are using the Bitbucket repo from Lesson 2, select “master”.
 

5. Build!

Click “Next” and Unity Cloud Build will automatically begin compiling.
 
You will automatically be notified when the build process has been complete.

4.
Appendix: Build Process Fundamentals

Introduction

This section will provide you with a high level overview of a game build process. By the end of this lesson, you will understand what a build process is and its components.

What’s a Build?

A usable version of your game. Players care about the build that goes on their device; often referred to as the public, live, or production build. For any given production build, there were hundreds - if not thousands - of builds generated by the game developer. These were made to ensure that the game works. Every one of these builds takes time to configure, compile, validate, and distribute.

What’s a Build Process (or Build Pipeline)?

A set of tools and steps that game developers use to create a build. If you’re a solo developer, the process is simple. Your code, assets, revisions, and build environment and machine, are all on your local computer. But a team environment requires tools and processes to determine the “authoritative” version of the game the team should be improving.

What does a Build Process consist of?

The typical elements are:
  • Repository (or “Repo”) where assets and code is stored. In professional environments, all files in a project are stored in a Source Control Management (“SCM”) system, so multiple team members can work with the same resources with minimal conflicts.
  • Build Environment pulls code and assets from the repository and compiles them into a working version of your game.
  • Distribution Service gets builds to users. For most of the game development life cycle, builds are distributed internally as it is validated.
  • Automation Engine monitors portions of the build process and takes automatic action; compiling builds as well as reports, notification, and distribution. In absence of an automation engine, the process is executed manually by one or more people on the team.
Here’s what a typical Build Pipeline looks like.

What’s Source Control?

Source Control (also commonly referred to as Version Control) is a system that gives you a way to ‘undo’ changes across multiple files, and collaborate on software projects with a team of people. Using source control is generally regarded as a ‘best practice’ for game development, since it protects you from accidentally losing hours of work, and makes it easier to try out different things with your code but roll back to a more stable version of your project if you need to rethink your approach.

How does Source Control work?

Depends on the specific Source Control Management system. A workflow for using Git for software development generally works like this.
  1. You make a repo (hosted somewhere) and put a Unity project in it
  2. You select a Git client (piece of software) that provides an interface for watching and tracking your changes
  3. You tell Git to ignore certain files (like your Library folder)
  4. You make some changes to your Unity project and save them in Unity
  5. You switch over to your Git client and it should tell you which files just changed
  6. Select those files and ‘commit’ then - this is basically akin to marking this version of your project so you can refer to it later.
  7. After 1 (or more) commits you ‘push’ your commits to the Gitl host / server, so that they are now backed up, and also visible to anyone else who is also working on the project. The final ‘push’ stage is what Unity Cloud Build sees when it is watching your project. That tells it to automatically kick off a new build.

Which Source Control Systems are supported by Cloud Build?

Unity Cloud Build supports the following Source Control Management systems (“SCM”):
  • Git
  • Subversion (“SVN”)
  • Perforce
  • Mercurial
For more information about specific systems, visit the following resources:
  • GitHub Bootcamp
  • BitBucket 101
  • Beanstalk - Getting Started with Subversion
  • Gamasutra Blogs - Git For Unity Developers
  • Using Version Control with Unity3D (Mercurial)

Do solo developers need a build pipeline?

Yes, even developers working by themselves can benefit from source control and a build pipeline. Source control gives you a backup of your project that you can recover from if your hard drive dies, or if you accidentally delete or break your project. And a build pipeline like Unity Cloud Build can save you tons of time by making builds for multiple platforms at once.