Sponsored By

Using Unity prefabs to avoid scene merge conflics

Quick Unity tip for small teams struggling with merge conflicts in large scenes.

Leon Arndt, Blogger

May 13, 2020

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

Hi, I am working in a small indie company working on our first title. We've recently started running into merge conflicts and needed a simple solution for the problem.

I am making this post because I could not find any other blogs mentioning this strategy. It's quite a basic solution but it has been helpful in various project settings.

 

The Problem

When working in large scenes, simultaneous changes to the scene are bound to happen at the same time. An artist will want to change a tree position while a designer is tweaking a pickup value. This can lead to merge conflicts which are always annoying to work with, even more if you don't have a lot of experience with version control. To minimize this problem, a prefab structuring approach will be presented.

 

The Solution

Top-level structuring gameObjects will be made into prefabs. 

This reduces the size of the objects which need to be merged. We are no longer dealing with giant scene files. Instead using scene groups (such as "gameplay", "environment", "cutscenes") we minimize the size of the conflicted files, making them easier to deal with.

 

The graphic below shows how we will change the scene structure:

 

And here is how this affects the scope of conflicted files due to changed objects:

 

In the above example you can see how when an object is changed in the environment it will only affect the environment prefab rather than the whole game scene.

Finally, here is an example overview of the scene hierarchy in Unity (please note that the groups have different names than in the graphics above)

Since Unity has added official support for nested prefabs, this solution has become even more feasible. Now prefabs such as the "World" group, may have a nested child prefab called "Player".

Drawbacks

Separating scenes into prefabs might feel unintuitive. Unity generally teaches us that prefabs are building blocks. In the case of prefab scene groups we generally won't reuse them anywhere.

Furthermore, each prefab needs an asset location. It might make sense to create a new "SceneGroups" folder for them or place them inside existing hierarchies, this is up to you.

Finally, this solution is only effective if its implementation is consistent. Almost without exception every top-level object in the scene should be a prefab. This can be annoying to set up when working with many different scenes.

I hope that was helpful and will reduce the number of headaches your team encounters when it comes to scene conflicts.

If you have any questions or comments, reach out to me on Twitter @NeoTalon

Read more about:

Blogs

About the Author

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

You May Also Like