Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Github Scene Merging

Discussion in 'Formats & External Tools' started by Amine654, Jan 7, 2021.

  1. Amine654

    Amine654

    Joined:
    Dec 17, 2017
    Posts:
    2
    So my team has been running into a problem with GitHub and Unity. Whenever we try to merge branches our scene gets screwed up and causes problems. Were trying to look for a better way to do this. Does anyone who has experience working in big teams know how to solve this? Like a workflow or process of moving work into the main branch that can solve this problem? Anything will help!
     
    awsapps likes this.
  2. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    255
    Github is a website, git is the tool you're trying to use.

    Scene merging is always troublesome, as Unity scenes will often change random values when you hit save. This causes merge complications and requires manual fixing. The best approach is to only have one person working actively on the scene at any time. The other person must actively discard their scene changes when unity makes these random changes.

    If you absolutely need to be two people working on the same level, consider working on two separate scenes, loaded in together additively. You can then merge the scenes when you're both done.
     
  3. Xarbrough

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    1,188
    To tackle this issue:

    Avoid working on the same scene or prefab. Other assets can also cause merge conflicts, but it's more problematic with files where data changes order (for example GameObjects moved in the hierarchy or things reordered within an array).

    You could simply have a convention among your team and use a symbolic lock (e.g. a physical token or maybe a Trello card, or just Slack/Discord/etc). Whoever has the token gets to edit the asset. Of course, this only works for the most important assets, because you can't have tokens for everything. We've successfully managed a 7-person student project this way because we only had a single "main" scene.

    To make locking more powerful, you can use tools such as file locking provided by source control. I don't think Git has this, maybe an extension, but I know that PlasticSCM, what we use, can lock files for editing. This makes it easy to take control of any asset.

    However, locking is never 100% safe, can always go wrong, and will disrupt your workflow. For my team, complete locking would be unacceptable, because why shouldn't I add a simple prefab reference to my scene while somebody else just tweaks camera settings? So we have a soft locking rule. For important assets, we announce editing (daily meeting and Slack), but we can still cooperate on the same asset if changes are expected to be mergeable.

    BUT: you can't just merge with Git's built-in merge tool, because this will likely break scenes and prefabs. Simple merge tools only understand lines (they are designed to merge simple text files like scripts). For Unity's YAML files (scenes/prefabs) this means, that the merge tool can potentially break the file format or destroy some data because it's not aware of the syntax that needs to be kept.

    To fix this issue, you need to use Unity's SmartMerge/YAMLMerge tool. This tool understands the file structure and will do a much better job at merging files. It's not perfect of course and you still need to be careful not to cause changes such as Person A edits values while Person B moves the component to a new GameObject. These things will cause duplicated components or one of the changes to be lost.
     
  4. Andre_Dev00

    Andre_Dev00

    Joined:
    May 22, 2015
    Posts:
    5
    The solution to your merge errors could be to create an additive scene manager. There are some youtube tutorial videos on that, although it can get very tricky to implement. I highly recommend doing it since you'll learn a lot! The concept is to have a level that is built out of multiple scenes, so when you edit one scene and someone modifies something from another scene, the changes can "merge" and you can work together.
    I've created a Unity tool that helps solve this issue, it has been recently published on the asset store!
    https://assetstore.unity.com/packages/tools/utilities/instant-subscenes-219913
     
  5. Bullzeye231

    Bullzeye231

    Joined:
    Aug 21, 2018
    Posts:
    3
    Hey guys,
    maybe it helps if I share our procedure how we usually tend to solve these problems.

    First of all there are pretty much three things ( in our case ) that causes merge conflicts:
    1. Script files
    2. Prefabs
    3. Scenes
    For script files its quite easy to solve the conflicts, just use a merge tool of your choice.
    For prefabs it is rather hard to deal with the .prefab files directly that's why we follow the approach of Jason Weimann
    so in general we say --take-theirs
    For Scenes we always use --take-ours.

    So briefly its like this
    1. Script files ( Resolve conflicts )
    2. Prefabs ( Take Theirs )
    3. Scenes ( Take Ours )
    Why is that a feasible approach?

    Our project is setup such that we don't have to deal with Scene conflicts at all. That can be achieved by having a single prefab in the scene holding the entire project. Making changes in the scene can then be considered as local changes to the developer ( a.k.a. Configuration changes ). Those changes should not go back to a master branch as they are not part of any module/prefab. Hence one can safely choose take-ours without loosing general project features as they should be stored within prefabs by convention.

    Leaving us with the prefab merge conflicts only.
    In case of prefab conflicts we do a manual merge as in the video of Jason Weimann.
    The bigger the project gets, the more prefabs one might get leading to less merge conflicts as
    long as one stays within its own prefab.
    As others stated a good team management definitely helps to reduce the amount of possible merge conflicts by assigning tasks that don't interfere or interact with each other.

    However in my opinion Unity definitely needs to deliver something for prefab merge conflicts here,
    so that we don't have to go the manual way. There exist approaches such as this which I find promising to be a good solution for the merge conflict of prefabs. Unity should pick something like this up and make an end to the manual merging.
     
    axg_wf likes this.