Gigi Labs

Please follow Gigi Labs for the latest articles.

Sunday, May 26, 2013

Unity3D: Setting up Source Control with SVN

Hi all! :)

Any experienced developer will tell you that source control using something like SVN is important for anything but the simplest projects. Source control allows you to keep a complete history of any changes you made, download them to different machines (great when working with other people on the same project), compare different versions of source files, and even revert to a specific version when necessary.

This article assumes you are already familiar with SVN, and are using a client such as TortoiseSVN. If you have no clue at this point, you can safely skip this article - future articles will not depend on it.

Start a new project and insert a cube into the game world via GameObject menu -> Create Other -> Cube, just so we have something in the game world.

Press Ctrl+S to save a .unity file into your project's Assets folder. This .unity file is called a Scene file - you can have several different scene files for different views such as the main menu, credits screen, and actual gameplay.

Now that you have something small in your project, you might want to commit it into SVN. The problem is that in your project's Library folder, there is this metadata folder with loads of weird subfolders:

...and each of those subfolders has a bunch of weird files:

Given that there are loads of such files and folders, and that they change very frequently, maintaining these in SVN will be a nightmare.

Fortunately, however, there is another way to use SVN with Unity.

From the Edit menu, go to Project Settings -> Editor. The Editor Settings will appear in the Inspector, on the right. From here, change the Version Control Mode from Disabled to Meta Files.

In Windows Explorer, navigate to your project folder:

Close Unity. The Temp folder will disappear.

Next, delete the Library folder. Don't worry - this will be created with the new meta files format (instead of all those weird files and folders) next time we open Unity.

You can now commit the project folder into SVN. If you're using TortoiseSVN, right click on the project folder, and select TortoiseSVN -> Add... and select all files and folders in the project. Then, right click the project folder and select SVN Commit... to commit the project into SVN:

Now, re-open the project in Unity by double-clicking the .unity file in your project's Assets folder. In the status bar at the bottom-left, you will see a message saying "Rebuilding Library because the asset database could not be found!":

Finally, to prevent you from accidentally committing the Library or Temp folders while you work, add both folders to the SVN ignore list by right-clicking on each folder and selecting TortoiseSVN -> Add to ignore list -> [Library/Temp]:

Once you have done this, the Temp and Library folders should carry an appropriate icon showing that they are excluded:

You can now continue making changes in Unity and committing them to your heart's content.

I hope that this was useful, and that you'll check back for other articles on Unity3D and on programming in general! :)


  1. Thanks for sharing. If you imported new asset in Asset Folder, don't you need to add the asset itself and the .meta file manually into repo?

    1. Yes, you just have to do a TortoiseSVN Add operation from the project folder. Then you commit the files just like you would when making any changes.


Note: Only a member of this blog may post a comment.