Unity 3D's component-based design model and race conditions

I’m having a bit of trouble with Unity 3D’s Component-based design model.

Here’s an example that demonstrates my problem:

class MyComponent : MonoBehaviour
{
    MyType entity;

    void Start() 
    {
	    entity = (MyType)FindObjectsOfType(typeof(MyType)).First();
    }
    
    void MyMethod() 
    {
	    var x = entity.SomeProperty; // <= NullReference exception
    }
}

// ....

var clone = (GameObject)Instantiate(original);
clone.GetComponent<MyComponent>().MyMethod();

Sometimes, not always though, MyMethod executes before Start so what I end up doing is move all the initializations I usually have in Start to MyMethod which is quite an ugly workaround:

    void Start() { }

    void MyMethod() 
    {
        entity = (MyType)FindObjectsOfType(typeof(MyType)).First();
	    var x = entity.SomeProperty; // <= now it's fine.
    }

My question is, what is the correct way of working with this pattern (without a constructor)?

"By default, the Awake, OnEnable and Update functions of different scripts are called in the order the scripts are loaded (which is arbitrary). "

The doc page goes on to tell you how to control the order. :wink:

You could also consider using Awake instead of Start. Docs say Awake should be used, like a constructor would be, to set up refrences etc., Start to do any communication between objects.