No, haven’t used those yet. I cannot even see the need: I use many additive scenes to avoid having anything significant that is shared among more than one scene!
Not only that I would NEVER EVER EVER EVER EVER!!!! put a singleton or manager in a scene… NEVER! It’s just not smart and it never was, and it never will be despite millions of examples and Unity trying to convince the world otherwise. It’s just BAD. See below.
WOW! Is that how scene presets / templates work?! That would completely defeat the typical use of a prefab in more than one scene. And if you are making a prefab of something used only in one scene, all you have done is undefined-ly split your hard work between two files, for no actual benefit. The only benefit to making a single-use prefab would be on a team so multiple people can update the prefabs used in a given large shared scene, but even then it is fraught with peril: changes made to the scene do NOT get committed to the prefab, YET they overwrite those data channels on the prefab, so someone could edit the prefab and see no changes in the scene.
Lots of red usually means you’re not source controlling everything you need to, usually the meta files.
You should enable visible file extensions in Windows. It has far too much value for developers.
Related snippets:
Additive scene loading is one possible solution:
https://discussions.unity.com/t/820920/2
https://discussions.unity.com/t/820920/4
https://discussions.unity.com/t/824447/2
A multi-scene loader thingy:
https://pastebin.com/Vecczt5Q
My typical Scene Loader:
https://gist.github.com/kurtdekker/862da3bc22ee13aff61a7606ece6fdd3
Other notes on additive scene loading:
https://discussions.unity.com/t/805654/2
Timing of scene loading:
https://discussions.unity.com/t/813922/2
Also, if something exists only in one scene, DO NOT MAKE A PREFAB out of it. It’s a waste of time and needlessly splits your work between two files, the prefab and the scene, leading to many possible errors and edge cases.
Two similar examples of checking if everything is ready to go:
https://discussions.unity.com/t/840487/10
https://discussions.unity.com/t/851480/4
PROPERLY CONFIGURING AND USING ENTERPRISE SOURCE CONTROL
I’m sorry you’ve had this issue. Please consider using proper industrial-grade enterprise-qualified source control in order to guard and protect your hard-earned work.
Personally I use git (completely outside of Unity) because it is free and there are tons of tutorials out there to help you set it up as well as free places to host your repo (BitBucket, Github, Gitlab, etc.).
You can also push git repositories to other drives: thumb drives, USB drives, network drives, etc., effectively putting a complete copy of the repository there.
As far as configuring Unity to play nice with git, keep this in mind:
https://discussions.unity.com/t/736093/3
I usually make a separate repository for each game, but I have some repositories with a bunch of smaller test games.
Here is how I use git in one of my games, Jetpack Kurt:
https://discussions.unity.com/t/807568/3
Using fine-grained source control as you work to refine your engineering:
https://discussions.unity.com/t/826718/2
Share/Sharing source code between projects:
https://discussions.unity.com/t/719810/2
Setting up an appropriate .gitignore file for Unity3D:
https://discussions.unity.com/t/834885/5
Generally setting Unity up (includes above .gitignore concepts):
https://thoughtbot.com/blog/how-to-git-with-unity
It is only simple economics that you must expend as much effort into backing it up as you feel the work is worth in the first place. Digital storage is so unbelievably cheap today that you can buy gigabytes of flash drive storage for about the price of a cup of coffee. It’s simply ridiculous not to back up.
If you plan on joining the software industry, you will be required and expected to know how to use source control.
“Use source control or you will be really sad sooner or later.” - StarManta on the Unity3D forum boards
Simple Singleton (UnitySingleton):
Some super-simple Singleton examples to take and modify:
Simple Unity3D Singleton (no predefined data):
https://gist.github.com/kurtdekker/775bb97614047072f7004d6fb9ccce30
Unity3D Singleton with a Prefab (or a ScriptableObject) used for predefined data:
https://gist.github.com/kurtdekker/2f07be6f6a844cf82110fc42a774a625
These are pure-code solutions, DO NOT put anything into any scene, just access it via .Instance!
The above solutions can be modified to additively load a scene instead, BUT scenes do not load until end of frame, which means your static factory cannot return the instance that will be in the to-be-loaded scene. This is a minor limitation that is simple to work around.
If it is a GameManager, when the game is over, make a function in that singleton that Destroys itself so the next time you access it you get a fresh one, something like:
public void DestroyThyself()
{
Destroy(gameObject);
Instance = null; // because destroy doesn't happen until end of frame
}
There are also lots of Youtube tutorials on the concepts involved in making a suitable GameManager, which obviously depends a lot on what your game might need.
OR just make a custom ScriptableObject that has the shared fields you want for the duration of many scenes, and drag references to that one ScriptableObject instance into everything that needs it. It scales up to a certain point.
If you really insist on a barebones C# singleton, here’s a highlander (there can only be one):
https://gist.github.com/kurtdekker/b860fe6734583f8dc70eec475b1e7163
And finally there’s always just a simple “static locator” pattern you can use on MonoBehaviour-derived classes, just to give global access to them during their lifecycle.
WARNING: this does NOT control their uniqueness.
WARNING: this does NOT control their lifecycle.
public static MyClass Instance { get; private set; }
void OnEnable()
{
Instance = this;
}
void OnDisable()
{
Instance = null; // keep everybody honest when we're not around
}
Anyone can get at it via MyClass.Instance.
, but only while it exists.