How to save and load a scene?

Discussion and help for Easy Save 3
Post Reply
Dominic
Posts: 1
Joined: Mon Sep 23, 2019 12:48 pm

How to save and load a scene?

Post by Dominic »

I've successfully made two checkpoints within one game level so if the player touches one of them he starts at that point the next time the scene is loaded, however if the player has entered a new level and reached a save point I want to be able so save and load the scene the player is in - I currently have a menu screen that links directly to level one, I want to be able to direct the player from the menu to the saved scene.

Not sure how to do that.

My current code for saving the player location within a scene:

void Start()
{

if (ES3.KeyExists("xPlayerPosition"))
{ xPlayerPosition = ES3.Load<float>("xPlayerPosition"); } else { xPlayerPosition = 217.09f; }
if (ES3.KeyExists("yPlayerPosition"))
{ yPlayerPosition = ES3.Load<float>("yPlayerPosition"); }
else { yPlayerPosition = 71.47f; }


transform.position = new Vector3(xPlayerPosition, yPlayerPosition, transform.position.z);
}


public void CheckPointReached()
{

xPlayerPosition = transform.position.x;
yPlayerPosition = transform.position.y;
ES3.Save<float>("xPlayerPosition", xPlayerPosition);
ES3.Save<float>("yPlayerPosition", yPlayerPosition);

}


And my Menu script just currently consists of:

public void LoadSavedLevel()
{
SceneManager.LoadScene(1);

}
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: How to save and load a scene?

Post by Joel »

Hi there,

You would essentially just need to save the scene name or ID to a key when the player enters the scene, and load this when necessary (using SceneManager.LoadScene to change the scene).

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