Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Question Unity Git repo breaks when cloned

Discussion in 'Editor & General Support' started by MariosZachariouUSTA, May 17, 2024.

  1. MariosZachariouUSTA


    Mar 28, 2024
    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.
  2. Spy-Master


    Aug 4, 2022
    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.
    Last edited: May 17, 2024
    CodeSmile likes this.
  3. CodeSmile


    Apr 10, 2014
    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.
    Spy-Master likes this.
  4. MariosZachariouUSTA


    Mar 28, 2024
    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:

    Code (Boo):
    1. # This .gitignore file should be placed at the root of your Unity project directory
    2. #
    3. # Get latest from
    4. #
    5. /[Ll]ibrary/
    6. /[Tt]emp/
    7. /[Oo]bj/
    8. /[Bb]uild/
    9. /[Bb]uilds/
    10. /[Ll]ogs/
    11. /[Uu]ser[Ss]ettings/
    13. # MemoryCaptures can get excessive in size.
    14. # They also could contain extremely sensitive data
    15. /[Mm]emoryCaptures/
    17. # Recordings can get excessive in size
    18. /[Rr]ecordings/
    20. # Uncomment this line if you wish to ignore the asset store tools plugin
    21. # /[Aa]ssets/AssetStoreTools*
    23. # Autogenerated Jetbrains Rider plugin
    24. /[Aa]ssets/Plugins/Editor/JetBrains*
    26. # Visual Studio cache directory
    27. .vs/
    29. # Gradle cache directory
    30. .gradle/
    32. # Autogenerated VS/MD/Consulo solution and project files
    33. ExportedObj/
    34. .consulo/
    35. *.csproj
    36. *.unityproj
    37. *.sln
    38. *.suo
    39. *.tmp
    40. *.user
    41. *.userprefs
    42. *.pidb
    43. *.booproj
    44. *.svd
    45. *.pdb
    46. *.mdb
    47. *.opendb
    48. *.VC.db
    50. # Unity3D generated meta files
    51. *.pidb.meta
    52. *.pdb.meta
    53. *.mdb.meta
    55. # Unity3D generated file on crash reports
    56. sysinfo.txt
    58. # Builds
    59. *.apk
    60. *.aab
    61. *.unitypackage
    62. *.app
    64. # Crashlytics generated file
    67. # Packed Addressables
    68. /[Aa]ssets/[Aa]ddressable[Aa]ssets[Dd]ata/*/*.bin*
    70. # Temporary auto-generated Android Assets
    71. /[Aa]ssets/[Ss]treamingAssets/aa.meta
    72. /[Aa]ssets/[Ss]treamingAssets/aa/*
    And .gitattributes

    Code (Boo):
    1. # Define macros (only works in top-level gitattributes files)
    2. [attr]lfs               filter=lfs diff=lfs merge=lfs -text
    3. [attr]unity-json        eol=lf linguist-language=json
    4. [attr]unity-yaml        merge=unityyamlmerge eol=lf linguist-language=yaml
    5. # Optionally collapse Unity-generated files on GitHub diffs
    6. # [attr]unity-yaml        merge=unityyamlmerge text linguist-language=yaml linguist-generated
    7. # Unity source files
    8. *.cginc                 text
    9. *.compute               text linguist-language=hlsl
    10. *.cs                    text diff=csharp
    11. *.hlsl                  text linguist-language=hlsl
    12. *.raytrace              text linguist-language=hlsl
    13. *.shader                text
    14. # Unity JSON files
    15. *.asmdef                unity-json
    16. *.asmref                unity-json
    17. *.index                 unity-json
    18. *.inputactions          unity-json
    19. *.shadergraph           unity-json
    20. *.shadersubgraph        unity-json
    21. # Unity UI Toolkit files
    22. *.tss                   text diff=css linguist-language=css
    23. *.uss                   text diff=css linguist-language=css
    24. *.uxml                  text linguist-language=xml linguist-detectable
    25. # Unity YAML
    26. *.anim                  unity-yaml
    27. *.asset                 unity-yaml
    28. *.brush                 unity-yaml
    29. *.controller            unity-yaml
    30. *.flare                 unity-yaml
    31. *.fontsettings          unity-yaml
    32. *.giparams              unity-yaml
    33. *.guiskin               unity-yaml
    34. *.lighting              unity-yaml
    35. *.mask                  unity-yaml
    36. *.mat                   unity-yaml
    37. *.meta                  unity-yaml
    38. *.mixer                 unity-yaml
    39. *.overrideController    unity-yaml
    40. *.playable              unity-yaml
    41. *.prefab                unity-yaml
    42. *.preset                unity-yaml
    43. *.renderTexture         unity-yaml
    44. *.scenetemplate         unity-yaml
    45. *.shadervariants        unity-yaml
    46. *.signal                unity-yaml
    47. *.spriteatlas           unity-yaml
    48. *.spriteatlasv2         unity-yaml
    49. *.terrainlayer          unity-yaml
    50. *.unity                 unity-yaml
    51. # "physic" for 3D but "physics" for 2D
    52. *.physicMaterial        unity-yaml
    53. *.physicsMaterial2D     unity-yaml
    54. # Exclude third-party plugins from GitHub stats
    55. Assets/Plugins/**       linguist-vendored
    56. # Unity LFS
    57. *.cubemap               lfs
    58. *.unitypackage          lfs
    59. # 3D models
    60. *.3dm                   lfs
    61. *.3ds                   lfs
    62. *.blend                 lfs
    63. *.c4d                   lfs
    64. *.collada               lfs
    65. *.dae                   lfs
    66. *.dxf                   lfs
    67. *.FBX                   lfs
    68. *.fbx                   lfs
    69. *.jas                   lfs
    70. *.lws                   lfs
    71. *.lxo                   lfs
    72. *.ma                    lfs
    73. *.max                   lfs
    74. *.mb                    lfs
    75. *.obj                   lfs
    76. *.ply                   lfs
    77. *.skp                   lfs
    78. *.stl                   lfs
    79. *.ztl                   lfs
    80. # Audio
    81. *.aif                   lfs
    82. *.aiff                  lfs
    83. *.it                    lfs
    84. *.mod                   lfs
    85. *.mp3                   lfs
    86. *.ogg                   lfs
    87. *.s3m                   lfs
    88. *.wav                   lfs
    89. *.xm                    lfs
    90. # Video
    91. *.asf                   lfs
    92. *.avi                   lfs
    93. *.flv                   lfs
    94. *.mov                   lfs
    95. *.mp4                   lfs
    96. *.mpeg                  lfs
    97. *.mpg                   lfs
    98. *.ogv                   lfs
    99. *.wmv                   lfs
    100. # Images
    101. *.bmp                   lfs
    102. *.exr                   lfs
    103. *.gif                   lfs
    104. *.hdr                   lfs
    105. *.iff                   lfs
    106. *.jpeg                  lfs
    107. *.jpg                   lfs
    108. *.pict                  lfs
    109. *.png                   lfs
    110. *.psd                   lfs
    111. *.tga                   lfs
    112. *.tif                   lfs
    113. *.tiff                  lfs
    114. *.webp                  lfs
    115. # Compressed Archive
    116. *.7z                    lfs
    117. *.bz2                   lfs
    118. *.gz                    lfs
    119. *.rar                   lfs
    120. *.tar                   lfs
    121. *.zip                   lfs
    122. # Compiled Dynamic Library
    123. *.dll                   lfs
    124. *.pdb                   lfs
    125. *.so                    lfs
    126. # Fonts
    127. *.otf                   lfs
    128. *.ttf                   lfs
    129. # Executable/Installer
    130. *.apk                   lfs
    131. *.exe                   lfs
    132. # Documents
    133. *.pdf                   lfs
    134. # ETC
    135. *.a                     lfs
    136. *.reason                lfs
    137. *.rns                   lfs
    138. # Spine export file for Unity
    139. *.skel.bytes            lfs
    140. .*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.

    Attached Files:

    Last edited: May 17, 2024
  5. Spy-Master


    Aug 4, 2022
    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.
    Code (csharp):
    1. #if UNITY_EDITOR
    2. using System.Linq;
    3. using UnityEngine;
    4. using UnityEditor;
    5. using UnityEditor.SceneManagement;
    6. using System.Collections.Generic;
    7. using UnityEditor.Callbacks;
    9. [CreateAssetMenu(menuName = "Utility/Scene Open List", fileName = nameof(SceneOpenList))]
    10. public class SceneOpenList : ScriptableObject
    11. {
    12.     public List<SceneAsset> scenes;
    13.     [OnOpenAsset]
    14.     public static bool OnOpenAsset(int instanceID, int line)
    15.     {
    16.         SceneOpenList asset = EditorUtility.InstanceIDToObject(instanceID) as SceneOpenList;
    17.         if (asset == null)
    18.         {
    19.             return false;
    20.         }
    21.         SceneSetup[] sceneSetups = asset.scenes
    22.           .Where(static s => s != null)
    23.           .Select(static s => new SceneSetup { isLoaded = true, path = AssetDatabase.GetAssetPath(s) })
    24.           .ToArray();
    25.         if (sceneSetups.Length == 0)
    26.         {
    27.             return true;
    28.         }
    29.         sceneSetups[0].isActive = true;
    30.         EditorSceneManager.RestoreSceneManagerSetup(sceneSetups);
    31.         return true;
    32.     }
    33. }
    34. #endif
    CodeSmile likes this.
  6. CodeSmile


    Apr 10, 2014
    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.
    Spy-Master likes this.
  7. MariosZachariouUSTA


    Mar 28, 2024
    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.

    Attached Files:

  8. Spy-Master


    Aug 4, 2022
    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.
    Last edited: May 17, 2024
  9. CodeSmile


    Apr 10, 2014
    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.
  10. MariosZachariouUSTA


    Mar 28, 2024
    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.
    CodeSmile likes this.