informa
2 MIN READ
Blogs

Using Unity prefabs to avoid scene merge conflics

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

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

Latest Jobs

Manticore Games

San Mateo, California
8.23.22
Senior Software Engineer - Mobile

Sony PlayStation

San Diego, California
6.23.22
Sr. Online Programmer

The Walt Disney Company

Glendale, California
8.1.22
Associate Marketing Manager - Walt Disney Games

Insomniac Games

Burbank, California
8.26.22
Accessibility Design Researcher
More Jobs   

CONNECT WITH US

Explore the
Subscribe to
Follow us

Game Developer Job Board

Game Developer Newsletter

@gamedevdotcom

Explore the

Game Developer Job Board

Browse open positions across the game industry or recruit new talent for your studio

Browse
Subscribe to

Game Developer Newsletter

Get daily Game Developer top stories every morning straight into your inbox

Subscribe
Follow us

@gamedevdotcom

Follow us @gamedevdotcom to stay up-to-date with the latest news & insider information about events & more