Load scene and set position for multiple saves

Discussion and help for Easy Save 3
Post Reply
zarriel
Posts: 1
Joined: Sun Jan 22, 2023 10:59 am

Load scene and set position for multiple saves

Post by zarriel »

Hello.
First of all, I have to say that EasySave is a great tool. Really good job!

I've seen that the solution to the problem of loading the character's saved position is to assign it in Awake/Start after loading the scene.
But... what if we have, for example, 5 different saves? How to tell in a new scene from which save I want to load the position (and everything else)?
Same, what if the player starts a new game but already has a savegame for the first scene? How to avoid the error so that the new game does not start in the position from the save?
I've seen that DontDestroyOnLoad can be used and assigned to a common object with the loading script. I could add a string variable and check if string !=null in Awake. Is this how I could achieve it or is there any other, better way?

EDIT:
I found solution.

Code: Select all

public string filename;
    
    private void Awake()
    {
        GameObject[] dataCatchers = GameObject.FindGameObjectsWithTag("DataCatcher");
        if (dataCatchers.Length > 1)
        {
            Destroy(this.gameObject);
        }
        DontDestroyOnLoad(this.gameObject);
    }
I created an empty object with a new tag. The filename value is assigned when loading the save. DontDestroyOnLoad causes the object to be preserved. If loop and array is to keep only one object left in the scene. In the main script in Awake, I search for an object, get the filename, and read in the data from a file named filename.

Maybe it'll help someone in the future.
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Load scene and set position for multiple saves

Post by Joel »

Glad you managed to find a solution.

Note that you can achieve a similar thing using a static variable as these persist between scenes.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Post Reply