Saving object existence

Discussion and help for Easy Save 3
Post Reply
User avatar
fanaei
Posts: 26
Joined: Thu Aug 23, 2018 7:54 am

Saving object existence

Post 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.
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Saving object existence

Post 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
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Post Reply