Finding inactive objects

Hi.

I’ve been trying to make my AI a little better, by checking if a light (that the player can turn on or off) is turned on or off, of course only when within range. Sometimes it finds the necessary object, sometimes it doesn’t. Here is a piece of code I wrote in C#:

public bool chasing;
public GameObject player;
public GameObject playerLight;

    void Start () {
    player = GameObject.FindGameObjectWithTag("Player");
    playerLight = GameObject.FindGameObjectWithTag("PlayerLight");
    }
    
    //in the update function...
    
    void Update () {
    ...
    float dist = Vector3.Distance(transform.position, player.transform.position);
    if(... || playerLight.gameObject.active && dist < playerLight.light.range){
    chasing = true
    }
    ...
    if(... && !playerLight.gameObject.active){
    chasing = false;
    }
    }

It seems really strange, how it sometimes happens to work, and other times it doesn’t…

OK, I fixed it by changing the intensity of the light and checking it in this script, so the object is never inactive. Works fine like that!