Should I make my own Start / Update?

Hi, guys.

Sometimes I’ve found myself struggling with some bugs due to the script order execution.
I know it can be properly set in “Edit/Project Settings/Script Execution Order”, but I don’t find it clean since it’s kind of hidden within Unity’s GUI and not inside your code.

So, I came up with something that it looks like a solution for me.

Instead of having one Start method in every object, I have only one Start method and I create a method named Initialize inside the rest of the objects. Initialize has basically the same function but it has to be manually called from the unique Start method. I know it can be a pain in the a**, but I think this gives you more control.

It would be something like this:

public class GameManager : MonoBehaviour 
{
    	void Start () 
    	{
    		InputManager.Instance.Initialize();
    		EnemyManager.Instance.Initialize();
    		EnvironmentManager.Instance.Initialize();
    	}

        void Update()
        {
            InputManager.Instance.EnterFrame();
    		EnemyManager.Instance.EnterFrame();
    		EnvironmentManager.Instance.EnterFrame();
        }
}

Obviously, I’m not planning to do this for EVERY object, but only for the important ones.
What do you think? What would be its downsides?

Thanks in advance.

If it works, well then it’s useful I suppose. However, you might have tightly-coupled references across these manager singletons, forcing you to use this strategy. I’d suggest you examine those references and load order to discover if you can abstract them somehow.

A quick idea: It might be a case of centralising key game ‘state’ variables into a new ‘state manager’ which are then operated on by independent managers, in contrast to ‘state’ hidden within each and dependent on execution order.

Here is my reflection based scheduler. It calls OnStart OnLogic OnGraphics OnLateGraphics OnPhysics OnGUI methods inside instances that it was told to watch, The methods can optionaly have float or double detlaTime parameter. Use the Add or Remove methods to add or remove instances.

You will have to make your own Instantiate method that automatically adds all instances into scheduler.
You can automatically add all scene instances at start by doing:

foreach (var mb in UnityEngine.GameObject.FindObjectsOfType(typeof(MonoBehaviour)))
{
    scheduler.Add(mb);
}

You can use this as a base to further add something like OnLateStart etc…

Also you seem to have problem with “god classes” singleton managers initilaization order. I use attributes on my mannager clases to assign them into a InitStage at which they are to be created.

public enum InitStage
{
	None = 0,
	Global = 1,
	NotConnected = 2,
	OnHasWorld = 3,
	OnHasWorldAndPlayer = 4,
}