Welcome back to “Continuous Improvement,” the podcast where we explore various challenges and solutions in the world of software development. I’m your host, Victor, and today we have an interesting topic to discuss - version control conflicts in Unity 3D game development.

So, recently, I’ve been working on a Unity 3D game project with a small team. It’s been a lot of fun, but we’ve encountered some issues with version control, specifically when using Git and GitHub. Merge conflicts have become quite common, and resolving them hasn’t been as simple as we initially thought.

Let me illustrate with an example. Imagine you have a merge conflict in a Unity scene file. It looks something like this:

Painful

Now, this type of conflict is not straightforward to manage. Deleting a section or performing a forced push won’t solve the problem. So, what can we do about it?

Let’s explore a solution I’ve discovered through trial and error. It’s not perfect, but it works. Firstly, open the Unity editor and navigate to:

Edit -> Project Settings -> Editor -> Select "Visible Meta files" in the version control mode.

This will help eliminate unnecessary local meta files from being pushed to the repository. But we’re not done yet. We need to add a .gitignore file to our project. Here’s an example of what it could look like:

/[Ll]ibrary/
/[Tt]emp/
/[Oo]bj/
/[Bb]uild/
/[Bb]uilds/
/Assets/AssetStoreTools*

# Autogenerated VS/MD solution and project files
ExportedObj/
*.csproj
*.unityproj
*.sln
*.suo
*.tmp
*.user
*.userprefs
*.pidb
*.booproj
*.svd

# Unity3D generated meta files
*.pidb.meta

# Unity3D Generated File On Crash Reports
sysinfo.txt

# Builds
*.apk
*.unitypackage

.DS_Store

Once you have added the .gitignore file, commit the changes. Now, let’s run a few commands to clean up the repository and make it ready for proper version control.

git rm -r --cached .
git add .
git commit -m "Fixed untracked files"

These commands will remove untracked files, add the necessary files, and create a commit with a specific message.

Lastly, Unity provides a tool called UnityYAMLMerge specifically designed for merging scene and prefab files. To enable this tool, we need to create a .gitconfig file with the following content:

[merge]
tool = unityyamlmerge

[mergetool "unityyamlmerge"]
trustExitCode = false
cmd = /Applications/Unity/Unity.app/Contents/Tools/UnityYAMLMerge merge -p "$BASE" "$REMOTE" "$LOCAL" "$MERGED"

By configuring Git with this .gitconfig file, we can leverage UnityYAMLMerge to handle these conflicts efficiently.

Keep in mind that when a teammate clones the project for the first time, they might see an empty scene. However, there’s no need to panic. By simply opening the saved main.scene (assuming it has been saved and committed previously), everything should work as expected.

I hope these tips and tricks can make your Unity 3D game development experience a little smoother. Wouldn’t it be great if Unity offered built-in source control integration like other IDEs? Ah, well, we can still make the most out of the tools we have.

That’s all for today’s episode of “Continuous Improvement.” If you have any questions or suggestions for future topics, feel free to reach out. Until next time, keep coding and striving for excellence. Goodbye!