Hi all,
I have tower library singleton it has all towers (120 unit) and their prefabs, videos pictures in it.
I use it as singleton reference.
But I am afraid it causes problems when lodinng unloading scenes.
I got black screen in some love level devices (3-4 gb ram)
how can I prevent it?
If you used DontDestroyOnLoad on the object, it will not be destroyed on scene unload.
If you didn’t, it will be destroyed.
hmm, but something is wrong my scene loads as I explained in my first message.
No idea about that problem but I’ve answered your primary question. Not enough to go one for the black screen issue.
Unity scene changing knows nothing about singletons.
The only thing Unity scene changing respects is root GameObjects being marked DontDestroyOnLoad().
The following pattern (with NOTHING ever placed in any scene) will work 100% of the time:
Simple Singleton (UnitySingleton):
Some super-simple Singleton examples to take and modify:
Simple Unity3D Singleton (no predefined data):
Unity3D Singleton with a Prefab (or a ScriptableObject) used for predefined data:
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
}
when can I call this function?
Anytime you want the singleton to go away and be recreated afresh at the next use.
I use it in my GameManagers at the START of the game.
The reason I don’t use it at the END of the game is that often I want info from the last game on the replay or menu screen(s), such as your last score.
That way it also handles if I quit the game early and forget to call it then.
hmm