Using singleton managers

If I have separate managers in my game to implement for:

  • Score tracking
  • Player spawning
  • Enemy spawning
  • Level management
  • Sound management

Is it a problem if I use one manager to rely on the function of another?

For example,

  1. The level manager selects a level in its Start() method
  2. The enemy spawning manager calls the level manager to select the level in its Start() method
  3. The sound manager calls the level manager to select the music track to play in its Start() method for the selected level

Would I run into problems because I cannot be certain that Step 1, 2, and 3 are executed in order?

Thank you

Order of Start() can’t be certain. So yea, this will probably cause problems. What you can do is define the script execution order:

Edit->Project Settings->Script Execution Order.

Now you can be certain that Level Manager will always be called first, then Enemy, etc.

Another solution, which might be better, is have a GameFlow class that calls each of the manager classes in the order you’d like. Instead of relying on individual Start()‘s, change them to “public void Init()”, In the gameflow class’ Start(), you can call each of the managers start/init functions.