Unity3D Android NullReferenceException for class properties during using Input.location.lastData

I found a very strange bug in Android build from Unity3D.

using UnityEngine;

public class Test : MonoBehaviour {
    public bool inited;

    void Start () {
        this.inited = false; // OK!
    }

    void Update()
    {
        this.inited = true; // OK!
    }
}

Yes… It’s simple and works :slight_smile:

BUT! If I read any data from Input.location.lastData like:

using UnityEngine;

public class Test : MonoBehaviour {
    public bool inited;

    void Start () {
        this.inited = false; // OK!
    }

    void Update()
    {
        if (this.inited && Input.location.status == LocationServiceStatus.Running)
        {
            float l = Input.location.lastData.latitude;
            Debug.Log("TEST [l] = " + l); // OK. Data present
            Debug.Log("TEST [this.inited] = " + this.inited); // !ERROR! NullReferenceException 
        }
    }
}

then links to the class properties disappear. Any ideas?

A bool cannot be null, thus you cannot get a null reference exception.

I also do not see a reason to debug that var from within the condition. You already know that it is true.

This code is for example only.
Real code is more complex.
In real code I tried write GPS data to inited (in Start) List var.
If I write something to List BEFORE

float latitudeValue = Input.location.lastData.latitude;

→ no problem.
If I try write latitudeValue (it’s AFTER accessing to Input.location.lastData) to the List var
→ NullReferenceException for List type class property.