strange and unexpected NullReferenceException error

hello everyone. i have a class as following:

using UnityEngine;
using System.Collections;

public class CheckPointManager : MonoBehaviour {
    public static CheckPointManager instance;

    public GameObject player;
    public bool CP1; // a boolean that returns true if the first checkpoint has benn reached
    public bool CP2;
    public Vector3 CP1SP; // check point 1 spawn position
    public Vector3 CP2SP;
    public float CP1ST; // check point 1 skip time
    public float CP2ST; // check point 2 skip time
   
    AudioSource audioSource;

    // Use this for initialization
    void awake () {
        DontDestroyOnLoad (gameObject);
        instance = this;
        audioSource = player.GetComponent<AudioSource> ();
    }
   
    // Update is called once per frame
    void Update () {
        if (!CP1 && audioSource.time > CP1ST) {
            CP1 = true;
            CP1SP=player.transform.position;
        }
    }
}

i have set the player GameObject in the inspector and i have checked everything on the inspector side and they are good. but still i get the error
“NullReferenceException: Object reference not set to an instance of an object”
when i double click the error it takes me to line 1 of the update function. specifically the problem seems to be invoking audioSource.time.

Does the player GameObject have an AudioSource attached? If it doesn’t then it would return null.

yes it does. and it is also active

Is the AudioSource in a child of the player?

i reference audioSource through many scripts without any problem. it is only checkPointManager thats problematic

no it is a component of player

Your “Awake” is in lowercase and never executing. It’s case sensitive.

1 Like

Good catch

oops, embarrassing. thanks a lot