Sponsored By

Unity Scene Diff Tool

How to write a Python script to make your Unity scenes diff-able and merge-able, so multiple team members can work on them at the same time.

Aaron Smith, Blogger

September 17, 2014

5 Min Read
Game Developer logo in a gray background | Game Developer

Greetings fellow Unity developers,

As you may have come across, text diffing and merging Unity scenes is not so easy.  Having a Unity scene be diff-able and merge-able is necessary for multiple team members to be able to edit it at the same time without losing changes.  Most teams either deal with this by letting only team team member at a time edit the scene file, or by buying Unity Pro ($1500).

Even with Edit->Project Settings->Editor->Asset Serialization set to “Force Text”, here’s the type of diff you can expect after changing a single value in your Unity scene.  The scrollbar shows how long the text is!:

before

Some solutions to this have been made, and sold on the Unity Asset Store.  My team tried two of these solutions.  However, neither of them just worked out of the box, and they were both extremely clunky.  It would have been more work to get these solutions to work for our team.

So, I figured out how to fix the problem with a simple Python script.  The Unity text file has lots of entities, which look like this:

— !u!196 &5                  <– (THE ENTITY TAG)

NavMeshSettings:

  m_ObjectHideFlags: 0

  m_BuildSettings:

    agentRadius: .5

    agentHeight: 2

    agentSlope: 45

    …

 

In scenes of moderate to large size, Unity basically randomizes the order in which it saves the entities.  So my Python script just sorts the entities based on their tag name.  Afterward, you get a much simpler diff:

after

The script was surprisingly easy to write.  Since it’s in Python, it works on both Windows and Mac, which is important since some of our team works on each platform.

Hope this tip works for you!

Aaron Smith
Chief Technical Officer
ZeroPoint Studios

Read more about:

Featured Blogs
Daily news, dev blogs, and stories from Game Developer straight to your inbox

You May Also Like