I am a traditional software developer who is dependent a lot on source code management systems like TFS and Git for project collaboration. However, lately my foray into Augmented Reality and HoloLens has taken me into the wild west of Unity and 3D game development and the source code management is not as simple here as one would like it to be.
Now Unity is awesome and gives you a lot of controls to play around with 3D models, prefabs and what not. But as soon as you start checking in your code into source control, you have a huge problem of missing files, missing scenes and what not. I have spent hours and hours just trying to get the latest version of my Unity project from TFS and still missing vital files. So, here is the attempt to help someone out there who might still be facing the same issue in this same environment.
To start with, the very first thing is, it is not possible to check-in the actual solution file to the TFS, because every time unity builds it, there is new solution file. Actually, it is not needed to check in as well.
The second confusing road block is, if you are a traditional Visual Studio user, you are used to just right clicking on the solution or project and saying “get latest version” or “check-in”. However that is not how it happens with Unity bound projects. Because the project is recreated every time when you build it from unity, it is not source bound. So you have to go to Team Explorer and click on Pending changes to check in latest change.
However, once you check-in, more often than not, some or other files, scripts, assets are missing in the source control. And this can be real pain in the ass. This is because whenever you create an asset, prefab, or script in the Unity, it is not by default added to your project in Visual Studio and in turns Team Explorer. To fix this, you have to make sure that the file you add to the project in the Unity is manually added to the TFS. To do so, after adding the file in the Unity, go to the respective folder in the Source Control Explorer inside Team Explorer, right click on the window, and then click on “Add items to folder”. Select the item you added in unity, click on Finish.
Then you will see this item in source control explorer. This is added to source control but not yet checked in. To check-in, right click on this item and select “check-in pending changes”. I know this is tiresome method to do so for every file you add through Unity, but that is how it is.
Now, another thing is this huge library folder which contains a large number of meta files and you don’t know what to do with them. Well, thankfully you don’t need to take care of them, as in Unity there is an option which takes care of meta files and source control integration.
Go to Unity –> Edit –> Project Settings –> Editor. In inspector, under version control, select the mode to be Visible Meta Files. Also while we are at it, set the Asset serialization to Force Text. TFS is better at integrating text files to source control than the binary files.
This still doesn’t insure that you absolutely won’t miss some binding in the unity when you get the latest version from the TFS (Can tell you from my own experience) However, this at least makes sure that all your files are on TFS. So I found out why I was missing some bindings finally. And here is why - Making the mode Visible Meta Files is not enough when you are dealing with the TFS. This will only ensure that you can see these meta files in your folder. However, to make sure that all bindings and information about your assets is available across all the systems that you are working with, you need to check in these files into source control explorer. Now they are not automatically added to souce control solution of your project, and you have to manually add them to your solution on Source Control. To do so, do what we have already done for normal asstes files. Go to Source Control Explorer in the Visual Studio. Go to the specific folder, right clicj and click on add items to the folder. Select Meta files, add them, and then check them in. That's all. This is enough to make sure that your Unity 3d project is available completely on the Team Foundation Server.
Hope it helps.