Warning: A non-numeric value encountered in /home/fixbyp5/public_html/wp-content/themes/Divi/functions.php on line 5752

Before I start; using Git to control source for Unity is not directly supported (though the concept is the same). Use this at your own risk and back up all of your data before attempting it.

Hello everyone. I was getting ready for Global Game Jam 2013 and decided to make this article explaining how to use Git as your source control for the Unity game engine. If you have used Unity before then you know how awesomely awesome it is. If you have ever used Unity with another person though, then you know how annoying source control can be. Unity gives you two options for source control: SVN (ho-hum) and the Unity Asset Server (expensive). If you are a poor and prefer Git over SVN then those two options won’t exactly tickle the senses. Luckily for us, we can make Git work to control our source just fine.

Before we start, be sure to have your Git environment set up. If you don’t know what Git is, then I encourage you to take the Git Crash Course located here. You will need to set up both your local environment and a Git repository (I recommend Github.com). Once done we can begin getting our Unity project ready. For this guide I am using information from Unity found here and I have modified a guide by Chris Danielson found here.

 

  1. Create a new project inside Unity and let’s call it InitialUnityProject. You can add any initial assets here or add them later on.
  2. Enable Meta files in Edit->Project Settings->Editor
  3. Quit Unity (We do this to assure that all the files are saved)
  4. Delete the Library directory inside your project directory
  5. Pull down or “clone” an empty repository to the same folder as the Unity project. To clarify, we will have a folder called “InitialUnityProject” (what we named our project) and inside will be the Unity “assets” and “ProjectSettings” folder. Also inside the “InitialUnityProject” folder will be a “.git” folder. There may also be a “.gitattributes” and “.gitignore” file. Once you have confirmed that all of the above items are in the same folder move on to the next step
  6. Now we need to create or modify (if it already exists) a .gitingore file in the “InitialUnityProject” folder. The code we will be putting in the file is listed below
  7. Commit the local copy of the Unity project now and sync with the repository. Confirm that the Unity files and folders exist on the remote server
  8. Open Unity. At this point it should rebuild the library. Ensure the project works (or continues to work if you did this with an already created project)

 

The .gitignore file will tell Git which files to leave local only and not sync to the server. We want to be sure to skip all library files and all scripting project files. We will allow those to be rebuilt whenever they need to be (should not be a problem). Our .gitignore file should look like this:

# Unity .gitignore file.
.DS_Store
Library
Library/*
*.csproj
*.sln
*.userprefs
Temp
*.pidb
Build

 

That’s it! Enjoy using Unity in a group setting with proper source control. Be sure to still coordinate with team members about working with Binary files. Nothing worse than making a bunch of changes to a .unity scene file only to discover that a colleague has done the same (you can’t merge those).

If you notice anything that I have missed or could have done better, please pass it on. Good luck and have fun!