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.
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.
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.
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/*
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.
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
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.
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.