Taking a Page from Godots Manual to Unity

A major problem for us with Unity has always been cooperating on scenes. There is no GUI support to resolve git merge conflicts and the pure text form of the scene files is barely human readable (it is to a certain extend, but it references all objects by hash, so it is impossible to know what gameobjects are referenced….). Especially in small projects like ludum dare games there are often only a small number of scenes – or even just one. In the last ludum dare this lead to the unfortunate situation of us coordinating who is allowed to work on the one single scene at all – and who must discard all own changes to it and reapply them after pulling… Needless to say this is not very efficient.

So what should we do instead, other than hoping for git support in Unity? We decided to take a page from Godots book and do what they have done from the beginning: use scenes for everything. If it deserves its own folder in the hierarchy it should get a scene of its own. UI? Put it in a scene on its own. The dialog UI inside the game UI? Another scene. The player character? Certainly needs its own scene.
Everything this needs to work is a small script that loads the required scenes additionally to the current one on load. In its most basic form the following 15 lines of code are enough:

using UnityEngine;
using UnityEngine.SceneManagement;

public class SceneLoader : MonoBehaviour {
  public List<string> requiredScenes;

  private void Awake() {
    foreach (var s in requiredScenes) {
      if (!SceneManager.GetSceneByName(s).isLoaded) {
        Debug.Log("Loading scene '" + s + "' additively");
        SceneManager.LoadScene(s, LoadSceneMode.Additive);
      }
    }
  }
}

Even recursion is solved automatically – but in a (somewhat counterintuitive) breadth-first fashion.

Does this really solve our problem? Well, not completely – but at least one programmer can work on the UI while another changes the Player while yet another works on the level and so on. We will see if it creates new problems as well ^^

Leave a Reply

Your email address will not be published. Required fields are marked *