Page 1 of 1

How can i make a null check for getkeys?

Posted: Wed Apr 24, 2024 7:42 pm
by Recktardeded
Hello, i would like to use getkeys, to initialize all of my vehicles in a array. The thing is, if there are no saved keys inside the folder i am trying to access i get a null reference error.
this is the code i use

Code: Select all

var keys = ES3.GetKeys(SceneManager.GetActiveScene().name + "_Vehicles.es3");//the line with the error
if (keys.Length > 0)
{
    for (int i = 0; i < keys.Length; i++)
    {
        var loadedContainer = keys[i];
        var loadedVehicleContainer = ES3.Load<VehicleContainer>(loadedContainer);
        GameObject newVehicleObject = Instantiate(loadedVehicleContainer.VehicleType_type.Vehicle_prefab);
        newVehicleObject.GetComponent<Vehicle_ObjectScript>().AssignVehicleContainer(loadedVehicleContainer);
        newVehicleObject.transform.position = GameManager.Instance.Manager_Vehicles.Vehicles_Owned_Spaces[i].transform.position;
        newVehicleObject.transform.rotation = GameManager.Instance.Manager_Vehicles.Vehicles_Owned_Spaces[i].transform.rotation;
        GameManager.Instance.Manager_Vehicles.Vehicles_Owned.Add(newVehicleObject);
    }
} 
and this is the error
NullReferenceException: Object reference not set to an instance of an object
ES3.GetKeys (ES3Settings settings) (at Assets/Plugins/Easy Save 3/Scripts/ES3.cs:1401)
ES3.GetKeys (System.String filePath) (at Assets/Plugins/Easy Save 3/Scripts/ES3.cs:1379)
Manager_Data.Vehicles_Owned_LoadAll () (at Assets/Scripts/Managers/Manager_Data.cs:154)
Thank you for your time!

Re: How can i make a null check for getkeys?

Posted: Thu Apr 25, 2024 7:35 am
by Joel
Hi there,

You don't appear to be using the latest version of Easy Save judging by your line numbers. Please try updating and see if that resolves your issue.

All the best,
Joel

Re: How can i make a null check for getkeys?

Posted: Fri Apr 26, 2024 8:21 pm
by Recktardeded
I've updated the asset and now i get a "File does not exist" error before getting the null error, thus i can use es3.fileexists for my intended purporse, thank you!