I’m using Unity 5.6.0f3. To recreate copy this code:
public AudioSource asrc;
public AudioClip ac;
private void Start() {
Debug.Log("asrc is null: "+ (asrc == null).ToString() + " audio is null " + (ac == null).ToString());
asrc.PlayOneShot(ac, 0.5f);
Debug.Log("All is fine");
}
Console:
asrc is null: True audio is null True
All is fine
It will generate exception when you run it on Android, it will generate an exception if you set audio Clip, and it will generate an exception if you change code to this (2nd line):
Debug.Log("asrc is null: "+ (asrc == null).ToString() + " audio is null " + (ac == null).ToString());
asrc = null;
asrc.PlayOneShot(ac, 0.5f);
Debug.Log("All is fine");
So basically only Unity_Editor, only when both are null, and when you haven’t set it to null via code. And game Object, to which this script is attached has no audio sources on it.
. I had audioSource playOneShot on Button click, same, it’s not related to being in Start() function.
And I tested this in another project, so you should be able to recreate this.