Unity Git repo breaks when cloned

This is the first time I use Unity professionally and something very strange is going on. The project contains 10 different interactive 2D scenes with their corresponding game objects and scripts, all is good in that regard. Now, I am trying to setup Unity with Git, I have gone through countless of “.gitignore” and “.gitattributes” templates as well as setting up git LFS currently I believe. For example, Library folder is not pushed to the remote repository. I push to master but any of my colleagues who try to clone the repository get an empty project when they open it in Unity Editor. All the assets, scenes and media is there however the editor shows the default “Untitled → Main Camera → Directional Light”. Indeed I deleted the local repository, and cloned it myself and I got the same issue. I have deleted the master and re-done, I have re-imported the project in the editor probably a million times therefore I am running out of ideas here.

I noticed that when I clone the repository and later copy paste the library folder from the backed-up/original/local repository into the cloned one, all the scenes appear just fine. This is more confusing to me because as stated (and researched online) it is widely accepted that the Library folder should not be pushed/shared. However how is my team suppose to clone the project with all the scenes appearing in? Do I need the library folder or not

If anyone has a similar issue or knows how to solve this please help me out. I can post anything you may as additional information, just comment and I shall do it.

Thank you in advance.

Which version of Unity and git are you using?

Are there any error messages in the Console view when opening a clone of the project from a clean state / after deleting Library?

What happens when one of the scenes is actually opened? Do you get any messages in the Console view?

What is Project Settings > Editor > Asset Serialization > Mode set to? It should be set to Force Text.

Compare a specific scene YAML in a text editor from the original copy and a clone, do they appear to have the same content?

Perhaps also share the Editor.log file from opening a clone of the project from a clean state.

The gitignore and gitattributes you’re using would also be helpful, along with the exact file / folder structure that you have in your git repo. You need at least the Assets, Packages, and ProjectSettings folders.

1 Like

Could you post a screenshot of the root contents of the project under source control?
And post the entire .gitignore file contents (in code tags please).

Perhaps you did exclude something that you shouldn’t have, like .meta files.

1 Like

There are no error messages at all in the editor and the Asset serialization is indeed set to “Force Text”. The Editor.log file is too large and also I do not see how it can play a role as it is local not remote?

Not to sure how to do that, could you please elaborate?

Pasting them below:

# This .gitignore file should be placed at the root of your Unity project directory
#
# Get latest from https://github.com/github/gitignore/blob/main/Unity.gitignore
#
/[Ll]ibrary/
/[Tt]emp/
/[Oo]bj/
/[Bb]uild/
/[Bb]uilds/
/[Ll]ogs/
/[Uu]ser[Ss]ettings/

# MemoryCaptures can get excessive in size.
# They also could contain extremely sensitive data
/[Mm]emoryCaptures/

# Recordings can get excessive in size
/[Rr]ecordings/

# Uncomment this line if you wish to ignore the asset store tools plugin
# /[Aa]ssets/AssetStoreTools*

# Autogenerated Jetbrains Rider plugin
/[Aa]ssets/Plugins/Editor/JetBrains*

# Visual Studio cache directory
.vs/

# Gradle cache directory
.gradle/

# Autogenerated VS/MD/Consulo solution and project files
ExportedObj/
.consulo/
*.csproj
*.unityproj
*.sln
*.suo
*.tmp
*.user
*.userprefs
*.pidb
*.booproj
*.svd
*.pdb
*.mdb
*.opendb
*.VC.db

# Unity3D generated meta files
*.pidb.meta
*.pdb.meta
*.mdb.meta

# Unity3D generated file on crash reports
sysinfo.txt

# Builds
*.apk
*.aab
*.unitypackage
*.app

# Crashlytics generated file
crashlytics-build.properties

# Packed Addressables
/[Aa]ssets/[Aa]ddressable[Aa]ssets[Dd]ata/*/*.bin*

# Temporary auto-generated Android Assets
/[Aa]ssets/[Ss]treamingAssets/aa.meta
/[Aa]ssets/[Ss]treamingAssets/aa/*

And .gitattributes

# Define macros (only works in top-level gitattributes files)
[attr]lfs               filter=lfs diff=lfs merge=lfs -text
[attr]unity-json        eol=lf linguist-language=json
[attr]unity-yaml        merge=unityyamlmerge eol=lf linguist-language=yaml
# Optionally collapse Unity-generated files on GitHub diffs
# [attr]unity-yaml        merge=unityyamlmerge text linguist-language=yaml linguist-generated
# Unity source files
*.cginc                 text
*.compute               text linguist-language=hlsl
*.cs                    text diff=csharp
*.hlsl                  text linguist-language=hlsl
*.raytrace              text linguist-language=hlsl
*.shader                text
# Unity JSON files
*.asmdef                unity-json
*.asmref                unity-json
*.index                 unity-json
*.inputactions          unity-json
*.shadergraph           unity-json
*.shadersubgraph        unity-json
# Unity UI Toolkit files
*.tss                   text diff=css linguist-language=css
*.uss                   text diff=css linguist-language=css
*.uxml                  text linguist-language=xml linguist-detectable
# Unity YAML
*.anim                  unity-yaml
*.asset                 unity-yaml
*.brush                 unity-yaml
*.controller            unity-yaml
*.flare                 unity-yaml
*.fontsettings          unity-yaml
*.giparams              unity-yaml
*.guiskin               unity-yaml
*.lighting              unity-yaml
*.mask                  unity-yaml
*.mat                   unity-yaml
*.meta                  unity-yaml
*.mixer                 unity-yaml
*.overrideController    unity-yaml
*.playable              unity-yaml
*.prefab                unity-yaml
*.preset                unity-yaml
*.renderTexture         unity-yaml
*.scenetemplate         unity-yaml
*.shadervariants        unity-yaml
*.signal                unity-yaml
*.spriteatlas           unity-yaml
*.spriteatlasv2         unity-yaml
*.terrainlayer          unity-yaml
*.unity                 unity-yaml
# "physic" for 3D but "physics" for 2D
*.physicMaterial        unity-yaml
*.physicsMaterial2D     unity-yaml
# Exclude third-party plugins from GitHub stats
Assets/Plugins/**       linguist-vendored
# Unity LFS
*.cubemap               lfs
*.unitypackage          lfs
# 3D models
*.3dm                   lfs
*.3ds                   lfs
*.blend                 lfs
*.c4d                   lfs
*.collada               lfs
*.dae                   lfs
*.dxf                   lfs
*.FBX                   lfs
*.fbx                   lfs
*.jas                   lfs
*.lws                   lfs
*.lxo                   lfs
*.ma                    lfs
*.max                   lfs
*.mb                    lfs
*.obj                   lfs
*.ply                   lfs
*.skp                   lfs
*.stl                   lfs
*.ztl                   lfs
# Audio
*.aif                   lfs
*.aiff                  lfs
*.it                    lfs
*.mod                   lfs
*.mp3                   lfs
*.ogg                   lfs
*.s3m                   lfs
*.wav                   lfs
*.xm                    lfs
# Video
*.asf                   lfs
*.avi                   lfs
*.flv                   lfs
*.mov                   lfs
*.mp4                   lfs
*.mpeg                  lfs
*.mpg                   lfs
*.ogv                   lfs
*.wmv                   lfs
# Images
*.bmp                   lfs
*.exr                   lfs
*.gif                   lfs
*.hdr                   lfs
*.iff                   lfs
*.jpeg                  lfs
*.jpg                   lfs
*.pict                  lfs
*.png                   lfs
*.psd                   lfs
*.tga                   lfs
*.tif                   lfs
*.tiff                  lfs
*.webp                  lfs
# Compressed Archive
*.7z                    lfs
*.bz2                   lfs
*.gz                    lfs
*.rar                   lfs
*.tar                   lfs
*.zip                   lfs
# Compiled Dynamic Library
*.dll                   lfs
*.pdb                   lfs
*.so                    lfs
# Fonts
*.otf                   lfs
*.ttf                   lfs
# Executable/Installer
*.apk                   lfs
*.exe                   lfs
# Documents
*.pdf                   lfs
# ETC
*.a                     lfs
*.reason                lfs
*.rns                   lfs
# Spine export file for Unity
*.skel.bytes            lfs
.*unity filter=lfs diff=lfs merge=lfs -text

Also the root directory

On the clean cloned project folder, I can drag and drop scenes (while inside the editor) from the bottom left corner Assets > Scenes to the left panel above it however does that mean anyone cloning a Unity project from Git has to do that manually? Perhaps this is not a bug after all but experience improvement? I can’t imagine having a having with hundreds if not thousands of scenes opened manually so you can see them all in the editor.

9840399--1415850--root directory.png

Just to see if there were errors or any other anomalies in the import process that aren’t presented in the Console or whatever reason. In the future, you can always attach files instead of putting them inline in the message.

If your entire problem is just that the editor doesn’t open the same set of scenes when cloned (and not an issue with the actual content being serialized as I’d thought), that’s just how things are, since the state for that seems to be stored in Library (LastSceneManagerSetup.txt). Every individual contributor to a project is supposed to open only the scenes that they’re supposed to be working on. With that said, you can always write a script to handle opening multiple scenes. Here’s an example script for something. You’d create an asset with Create > Utility > Scene Open List and add the scenes you need to open. Then, any time you want to open that list of scenes, double-click that asset.

#if UNITY_EDITOR
using System.Linq;
using UnityEngine;
using UnityEditor;
using UnityEditor.SceneManagement;
using System.Collections.Generic;
using UnityEditor.Callbacks;

[CreateAssetMenu(menuName = "Utility/Scene Open List", fileName = nameof(SceneOpenList))]
public class SceneOpenList : ScriptableObject
{
    public List<SceneAsset> scenes;
    [OnOpenAsset]
    public static bool OnOpenAsset(int instanceID, int line)
    {
        SceneOpenList asset = EditorUtility.InstanceIDToObject(instanceID) as SceneOpenList;
        if (asset == null)
        {
            return false;
        }
        SceneSetup[] sceneSetups = asset.scenes
          .Where(static s => s != null)
          .Select(static s => new SceneSetup { isLoaded = true, path = AssetDatabase.GetAssetPath(s) })
          .ToArray();
        if (sceneSetups.Length == 0)
        {
            return true;
        }
        sceneSetups[0].isActive = true;
        EditorSceneManager.RestoreSceneManagerSetup(sceneSetups);
        return true;
    }
}
#endif
1 Like

You mean dragging scenes into the Build Settings (in Unity 6: Build Profile) window so they are included in the build?

What do you mean by “open”? You are referring to the list of scenes in the build, are you?

You can make a build script that auto-includes scenes in a specific folder or following a naming scheme. But generally I would be cautious with a project that has hundreds of scenes in it. Perhaps this level of granularity isn’t needed but you rather want these scenes to be prefabs.

The common assumption “one scene per level” is quite often misleading. You can just as well have “one scene all levels” even up to “one scene for everything”. You can additively load/unload scenes or simply do the same with prefabs that are instantiated and destroyed as needed, or set active/inactive.

1 Like

On the original-project image you can see there are 10 scenes all laid out and ready to work with. On the latter image (cloned.png) which is the cloned repo with no Library folder, you have a blank project. Now as previously stated and shown in the image, I can drag and drop one by one those scenes onto the left panel so that they resemble the original-project image however is that the intended working flow? Why can’t the cloned project open all scenes once imported in the Editor? Perhaps a silly question but just trying to wrap my head around it.


That’s the default way to do it that you get out of the box. As I mentioned and demonstrated in my previous message, you can also script the heck out of it depending on what you need. I’ll again say that every team member has a different role and should be opening the scenes they’re working on, and most productions are organized in a way that scenes are modular enough to be worked on one at a time or in small related groups, so this workflow makes sense compared to making the default behaviour be opening one set of scenes automatically.

You are using the additive scene workflow. It hit me as a surprise initially because my expectation was also that these additive scenes would persist, but they don’t. I can’t recall the rationale for this but it sort of made sense after I researched it.

The solution is relatively straightforward.

While editing, you add only what you need. You can use an editor script to help you with that.

At runtime, you load exactly what is needed. There is no “debug” scene getting added unless you explicitly load that. A scene-managing MonoBehaviour can help you with that.

I’ve set up my scripts so I can drag & drop additive scenes to a list for every individual scene, or for every subtree, so that I can just enable an object and it loads those scenes and when disabled, it unloads them.

I use SceneReference to be able to drag/drop scene assets in the Inspector while providing the scene name as string at runtime.

Well, I can only apologise for wasting everyone’s time, I did not know (nor indeed made sense to my brain) that this was the intended use. In every platform/framework I worked on, no matter how big/small it was, the entire project was loaded at once. Now I know, you live and learn something everyday.

Cheers anyway for helping me out.

1 Like