Using a version control system makes it easier for a user (or multiple users) to manage their code. It is a repository of files with monitored access. In the case of Unity, this is all the files associated with a Unity project. With version control, it is possible to follow every change to the source, along with information on who made the change, why they made it, and what they changed. This makes it easy to revert back to an earlier version of the code, or to compare differences in versions. It also becomes easier to find out when a bug first occurred, and with what changes might have caused it.
Get your version control software setup according to its instructions, then follow these steps:
Copy an existing project into the workspace, or start Unity and create a new project in the workspace.
Open the project and go to Edit > Project Settings > Editor.
Under Version Control, choose your Mode according to the version control system that you chose.
Fill out your version control settings, such as username / password / server / workspace.
Keep Automatic add checked if you want your files to be automatically added to version control when they’re added to the project (or the folder on disk). Otherwise, you need to add new files manually.
You have the option to work offline. This mode is only recommended if you know how to manually integrate changes back into your version control software (Working offline with Perforce).
You can edit the Asset Serialization, Default Behaviour Mode and Sprite Packer options to suit your team’s preferences and choice of version control.
Click Connect and verify that “Connected” is displayed above the Connect button after a short while.
Use your standard client (e.g. p4v) to make sure that all files in the Assets and ProjectSettings folders (including files ending with .meta) are added.
N.B. At any point you can go to the Prefences menu and select External Tools and adjust your Revision Control Diff/Merge tool.
At this point you should be able to do most of the important version control operations directly by right-clicking on the assets in the project view, instead of going through the version control client. The version control operations vary depending on which version control you choose, this table shows what actions are directly available for each version control:
|Version Control Operation||Description||Perforce||Plastic SCM|
|Check Out||Allows changes to be made to the file||Yes||Yes|
|Diff against head||Compares differences between file locally and in the head||Yes||Yes|
|Get Latest||Pull the latest changes and update file||Yes||No*|
|Lock||Prevents other users from making changes to file||Yes||No**|
|Mark Add||Add locally but not into version control||Yes||Yes|
|Resolve Conflicts||To resolve conflicts on a file that has been changed by multiple users||Yes||No***|
|Revert||Discards changes made to open changed files||Yes||Yes|
|Revert Unchanged||Discards changes made to open unchanged files||Yes||Yes|
|Submit||Submits current state of file to version control||Yes||Yes|
|Unlock||Releases lock and allows changes to be made by anyone||Yes||No**|
* To get the latest changes and update the file using Plastic SCM, you need to use the version control window.
** Locking and Unlocking using Plastic SCM require you to edit a specific Plastic SCM lock file externally, see the Plastic SCM Integration page for more information.
*** Conflicts are shown within the version control menu but resolved in the Plastic SCM GUI.
You can overview the files in your changelist from the Version Control Window (Window->Version Control). It is shown here docked next to Inspector in the editor:
The ‘Outgoing’ tab lists all of the local changes that are pending a commit into version control whereas the ‘Incoming’ tab lists all of the changes that need to be pulled from version control.
By right clicking assets or changelists in this window you perform operations on them. To move assets between changelists just drag the assets from one changelist to the header of the target changelist.
The following icons are displayed in Unity editor to visualize version control status for files/assets:
|File added locally||Pending add into version control|
|File added to version control by another user||Pending add into version control|
|File is checked out by you||Checked out locally|
|File is checked out by another user||Checked out remotely|
|There has been a conflict merging this file||Needs to be resolved|
|File has been deleted by you||Pending deletion in version control|
|File has been deleted by another user||Pending deletion in version control|
|File is not yet under version control||n/a|
|File is locked by you||Cannot be modified by other users|
|File is locked by another user||Cannot be modified by you|
|Another user has checked in a new version of this file||Use “Apply Incoming Changes” to get latest version|
|The server is requesting the version control status of this file, or is waiting for a response||You can only see this when using a centralised version control system like Perforce|
Things to note:
When working with assets, Unity automatically checks out both the asset file as well as the associated .meta file. In most situations however, the .meta file is not modified, which might cause some extra work e.g. when merging branches at a later point.
Unity supports working in offline mode, e.g. to continue working without a network connection to your version control repository.
Unity supports asynchronous version control status queries for some version control providers, such as Perforce. This option allows those providers to update the version control status of files without stalling Unity. Use this option when the connection to your version control server has high latency.
Note: Only status queries are asynchronous. Operations that change the state of files, or require up-to-date knowledge of file status, are performed synchronously.
If Unity cannot commit your changes to your version control client, (for example, if the server is down or license issues occur), your changes are stored in a separate changeset.
To learn more about working with the Asset Server (Unity’s internal version control system), see documentation on the Asset Server.
To work with a version control system unsupported by Unity, select MetaData as the Mode for Version Control in the Editor Settings. This allows you to manage the source Assets and metadata for those Assets with a version control system of your choice. For more on this, see documentation on External Version Control Systems.
2017–02–12 Page amended with limited editorial review
Documentation on asynchronous version control status queries added in Unity 2017.3.