OnEnable called before Awake

I had some weird behavior in my code which took some time to find the problem.
I have two scripts, one works with the data OnEnable, other on Awake, i added debugs to see execution order.

public class Player : MonoBehaviour {

    private void OnEnable(){
		Debug.Log ("registering events");
	}
}

public class InputManager : MonoBehaviour{
	private void Awake(){
		Debug.Log("awake");
    }
}

Console

56149-8529368469e03851f63a6bfde3fb50cd.png

How is this possible? Docs clearly show that OnEnable is called after Awake.
All gameobjects components live on are active and components enabled.

Project came from other dev, is it possible he changed execution order (not sure if thats possible).
Ive never seen anything like this.

Edit:

I just created two empty scripts A and B with only this code in each of them, each on its own dummy gameobject, execution order is correct for them. I even attached these components to same gameObjects, execution order is still correct, but reversed on old scripts!

Actually Unity doesn’t do all awake() and then all OnEnable().
For each script that it loads he does Awake() OnEnable and move on to the next script. So your problem is that Unity load Player first and then InputManager.

56152-unityawakeonenable.png

But there is a way to fix this built in Unity : The script Execution Order that you can find under Edit/ProjectSettings/Script Execution Order ( Unity - Manual: Script Execution Order settings ).

Hope that helped ya figure it out.

The order in which the scripts are placed in the “Hierarchy” affects their execution order as well. Meaning moving the object with script attach up on the hierarchy in the editor will determine what executes before and after it.