I have a complex scenario which I have reduced to the following problem:
I have a Cube in my Unity scene. This cube has the following script on it:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MainScript : MonoBehaviour
{
public OtherScript TheOtherScript;
public void OnGUI()
{
if (GUI.Button(new Rect(0, 0, 50, 50), "Load something"))
{
this.TheOtherScript.LoadFile();
}
}
}
The script "OtherScript" looks like this:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class OtherScript : MonoBehaviour
{
private string _sPath;
public void Awake()
{
_sPath = Application.persistentDataPath + "/somefilename.dat";
}
public void Start()
{
_sPath = Application.persistentDataPath + "/somefilename.dat";
}
public void LoadFile()
{
if (_sPath == null)
{
Debug.Break();
}
//do something with _sPath
}
}
I have created an empty GameObject to my scene, and I have added such a script to it:

I have then put a reference to empty GameObject to the Cube's "OtherScript" slot:

The problem that I'm experiencing is that "TheOtherScript"'s start / awake has not been called when this button is pressed:
if (GUI.Button(new Rect(0, 0, 50, 50), "Load something"))
{
this.TheOtherScript.LoadFile();
}
Neither Awake nor Start is called on this script.
Which event could I react to in this case for initialization?