There is. But please refrain from necro-posting to old threads and instead make your own… it’s FREE!
How to report your problem productively in the Unity3D forums:
http://plbm.com/?p=220
This is the bare minimum of information to report:
- what you want
- what you tried
- what you expected to happen
- what actually happened, especially any errors you see
- links to documentation you used to cross-check your work (CRITICAL!!!)
The actual problem in this thread can be best thought of it as an object lifecycle issue.
Identify the range of time you want each object to live.
If it must exceed a single frame load, make it DDOL.
What you describe sounds sort of like a player database, so probably:
- create the object at app start (or player login) and NEVER remove it, NEVER make another one
- before the app exits, save all you want to save
If it’s something that lives for X frames, then goes away, like a GameManager, then make it go away when you don’t want it anymore.
ULTRA-simple static solution to a GameManager:
https://forum.unity.com/threads/i-need-to-save-the-score-when-the-scene-resets.1168766/#post-7488068
https://gist.github.com/kurtdekker/50faa0d78cd978375b2fe465d55b282b
OR for a more-complex “lives as a MonoBehaviour” solution…
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!
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.
And if you really insist on barebones C# singleton, here’s a Highlander:
https://gist.github.com/kurtdekker/b860fe6734583f8dc70eec475b1e7163