Trouble loading game save data with BlazeSave after uploading a new Steam build
First time posting here, and feeling like my C# skills are pretty rudimentory. I am working on my first game BioEntity, a 2D platformer to release on Steam for Windows and macOS.
I was previously using PlayerPrefs to save game data, but I recently implemented BlazeSave to persistently save user data when I build in Unity and then upload to Steam. Saves are stored within the 'Saves' folder in the main project folder alongside 'Assets' and 'Library.' This works in the Unity Editor.
However, uploading new builds to Steamworks and downloading the update does NOT allow me to access my old save game folders. Code should grey out the 'Continue' button if there are no Saves and make it active (green) if the 'Saves' folder contains any subfolders (containing save game data files). When you click 'Continue', a UI Dropdown menu should populate with the names of all the sub directories inside of 'Saves', so you can select your save game file and load it.
Instead, 'Continue' is active but shows the default options (blank), not the save names. Only after I create a new game does it then appear in the Continue dropdown menu.
The idea is that pushing a new build to Steamworks should not erase or overwrite existing save game folders; they should persistently stay within 'Saves.'
Here is the relevant code from MainMenu.cs that runs at the start of the game:
public int levelBeaten;
public GameObject audioFade;
public AudioSource audioSource;
public GameObject NewGameButton;
public GameObject ContinueButton;
public GameObject HowToPlayButton;
public GameObject ControlsButton;
public GameObject ExtrasButton;
public GameObject AreYouSure;
public GameObject NewGameWindow;
public GameObject YesButton;
public GameObject NoButton;
public GameObject StartButton;
public GameObject BackButton;
public GameObject InputField;
public GameObject ContinueWindow;
public Dropdown saveGameFolders;
public AudioClip labMusic;
string lastSelected;
Text SaveName;
DirectoryInfo dir;
DirectoryInfo[] info;
void Awake()
{
SaveSystem.Load();
//Load the highest level beaten from Preferences
levelBeaten = SaveSystem.levelBeaten;
//Hide the Continue Window
ContinueWindow.SetActive(false);
//Get the Save Directory
dir = new DirectoryInfo(System.IO.Directory.GetCurrentDirectory() + "\\Saves");
info = dir.GetDirectories();
Debug.Log("Dir: " + dir);
//If no saves, set 'Continue' to grey and select New Game Button. If there are saves, set to green and select Continue BUtton.
if (info.Length == 0)
{
EventSystem.current.SetSelectedGameObject(NewGameButton);
Text continueText = ContinueButton.GetComponentInChildren<Text>();
continueText.color = new Color(0.5f, 0.5f, 0.5f);
}
else
{
EventSystem.current.SetSelectedGameObject(ContinueButton);
Text continueText = ContinueButton.GetComponentInChildren<Text>();
continueText.color = new Color(0f, 1f, 0f);
}
}
public void LoadGameWindow()
{
ContinueWindow.SetActive(true);
if (info.Length == 0)
{
ContinueWindow.SetActive(false);
EventSystem.current.SetSelectedGameObject(ContinueButton);
} else {
//Clear the Save Games dropdown menu
saveGameFolders.ClearOptions();
//For each folder in the Save directory, load the name as a dropdown menu item
foreach (DirectoryInfo f in info)
{
Debug.Log("Save Folder: " + f);
Dropdown.OptionData saveGameName = new Dropdown.OptionData();
string saveNameDisplay = Path.GetFileName(f.ToString());
saveGameName.text = "" + saveNameDisplay;
//saveGameName.text = "" + f;
saveGameFolders.options.Add(saveGameName);
}
saveGameFolders.value = -1;
EventSystem.current.SetSelectedGameObject(StartButton);
}
}
public void LoadGame()
{
//Load from /Saves/[the selected dropdown item]
SaveSystem.SaveName = "Saves/" + saveGameFolders.options[saveGameFolders.value].text;
Debug.Log("Save Folder:" + SaveSystem.SaveName);
Debug.Log("SaveName = " + SaveName);
//Load from SaveSystem and go to the Minimap scene
SaveSystem.Load();
SceneManager.LoadScene("Blob-Minimap", LoadSceneMode.Single);
}
And SaveSystem.cs looks like this:
public static int levelBeaten;
public static int currentLevel;
...
public static void NewGame()
{
currentLevel = 1;
levelBeaten = 0;
...
}
public static void Load()
{
levelBeaten = BlazeSave.LoadData<int>("LevelBeaten.bin", SaveName, null, true);
currentLevel = BlazeSave.LoadData<int>("CurrentLevel.bin", SaveName, null, true);
...
}
public static void Save()
{
BlazeSave.SaveData("LevelBeaten.bin", levelBeaten, SaveName, null, true);
BlazeSave.SaveData("CurrentLevel.bin", currentLevel, SaveName, null, true);
...
}
I really appreciate any help I can get on properly implementing save games; this has been a constant source of frustration for me. I am super worried that I will release my game and any patches will prevent players from loading their save games.
Thanks!
Your answer
Follow this Question
Related Questions
Writing dropdown selections to file 1 Answer
Options menu won't work 0 Answers
How can I set up an in-game menu? 1 Answer
How to make folding menu? 0 Answers
DropDownList don't close at game paused 0 Answers