Skip to main content
2 of 3
added 187 characters in body

First of all check that your Unity version is not an Alpha one. In that case anything might happen.

If your unity version is anyone of 2019.1 or previous everything will be working as expected.

Awake

Awake is called after all objects are initialized

Start

However, Awake is called when the script object is initialised, regardless of whether or not the script is enabled. Start may not be called on the same frame as Awake if the script is not enabled at initialisation time.

This means your Awake and Start are called properly (because your game object starts enabled). You may just add a Debug.Log statement to check them.

public void Awake()
{
    Debug.Log("Awake Called");
    _sPath = Application.persistentDataPath + "/somefilename.dat";
}
public void Start()
{
    Debug.Log("Start Called");
    _sPath = Application.persistentDataPath + "/somefilename.dat";
}

public void LoadFile()
{
    if (_sPath == null)
    {
        Debug.Break();
    }
    //do something with _sPath
    Debug.Log(_sPath);
}

The issue relies most likely on MainScript method.

Also:

  • Make sure the scripts are saved before launching play
  • Make sure the scripts are attached to the Game Objects before going in play mode