Page 1 of 1

Saving object existence

Posted: Wed Dec 18, 2019 5:35 am
by fanaei
Hi Joel,
I wanna save the existence of enemies. And I'm using this manual way:

Code: Select all

public bool Exist;
    void Awake()
    {
        Exist = ES3.Load<bool>("Exist" + gameObject.name + transform.position.x.ToString(), true);
        if (Exist == false)
        {
            Destroy(gameObject);
        }
    }

    private void OnDestroy()
    {
        Exist = false;
        ES3.Save<bool>("Exist" + gameObject.name + transform.position.x.ToString(), Exist);
    }
I wanted to know if there's any better way to do it. Because I'm worried if the saving process makes some lags on gameplay.

Re: Saving object existence

Posted: Wed Dec 18, 2019 7:23 pm
by Joel
Hi there,

A more efficient way would be to add all of your GameObjects to an array, and then create an array of bools which determines whether it exists or not. This would require a single key in the file rather than one for each GameObject, which would significantly improve performance. This would require your GameObjects to be in the same order in the array on each load.

All the best,
Joel