Hi! I want ask is everyone assign a same GameManager script in a empty object of all scenes?
I do that because I put Load scene function in GameManager script and I also use Singleton for it, but that cause my a problem. Once a while( maybe 0.3% of times) when other script call GameManager the result is GameManager = null.
If you use a singleton why have it in all scenes?
I find it best to start all singletons in a preMainMenu scene so you never have a problem with multiple instances.
Its probably null because it’s start or awake method gets called later than your other scripts. You could put it first in the script execution order or just let the game manager persist through all the scenes…
Some super-simple Singleton examples to take and modify:
Simple Unity3D Singleton (no predefined data):
Unity3D Singleton with Prefab used for predefined data:
These are pure-code solutions, do not put anything into any scene, just access it via .Instance!
Thank you
1 Like