Skip to content

Instantly share code, notes, and snippets.

@travelhawk
Last active April 14, 2022 13:08
Show Gist options
  • Save travelhawk/1f9c37bfdb8aabc63ab671e6df6fcd47 to your computer and use it in GitHub Desktop.
Save travelhawk/1f9c37bfdb8aabc63ab671e6df6fcd47 to your computer and use it in GitHub Desktop.

Merging Unity3D scenes

Unity3D scenes and prefabs cannot not be merged automatically by default. Working on one scene / prefab at the same time can cause issues when a merge conflict happens. Usually that means that one version needs to be discarded or the files need to be merged manually (which isn't easy).

However, Unity provides the UnityYAMLMerge tool with each Unity installation to merge scenes and prefabs semantically for manual setup. This is also called Smart Merge. The tool can be accessed from the command line and is also available to third-party version control software like Git, etc. To setup the smart merge for Git, follow the following steps.

How to Setup

Add the following text to your .git/config file inside your project folder or to your <path to user folder>/.gitconfig.

[merge]
tool = unityyamlmerge

[mergetool "unityyamlmerge"]
trustExitCode = false
cmd = '<path to unity folder>\Editor\Data\Tools\UnityYAMLMerge.exe' merge -p "$BASE" "$REMOTE" "$LOCAL" "$MERGED"

Handling Merging Conflicts

The smart merge only works when different changes doesn't occur in the same gameObjects / components. If so, there still will be a merge conflict which needs to be solved manually. To do that we need to configure a fallback merge tool. We can use any, but here I decided to use the free visual appealing merge tool P4Merge. This can be downloaded here: https://www.perforce.com/downloads/visual-merge-tool

Here is how to hook up the merge tool as global merge tool. Type the following in the cmd:

git config --global merge.tool p4merge
git config --global mergetool.p4merge.path 'C:/Program Files/Perforce/p4merge.exe'

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment