So I followed the List Files in A Directory video, but now I am running into Null Reference exceptions. I am also unable to continue the game. I added the mini fix at the end of the New Game and PlayerPrefs Video. This is the error message I am getting
NullReferenceException: Object reference not set to an instance of an object
RPG.UI.SaveLoadUI.OnEnable () (at Assets/Scripts/UI/SaveLoadUI.cs:23)
Line 23 is this one:
foreach (string save in savingWraper.ListSave())
{
GameObject buttonInstance = Instantiate(buttonPrefab, contentRoot);
TMP_Text textComp = buttonInstance.GetComponentInChildren<TMP_Text>();
textComp.text = save;
Button button = buttonInstance.GetComponentInChildren<Button>();
button.onClick.AddListener(() =>
{
savingWraper.LoadGame(save);
});
}
I added some debug logs and when I click the LOAD button I get my debug code here showing up.
if (!GetComponent<SavingSystem>().SaveFileExists(GetCurrentSave()))
{
Debug.Log("NO SAVING SYSTEM");
return;
}
my Continue game looks like this
public void ContinueGame()
{
if (!PlayerPrefs.HasKey(currentSaveKey))
{
Debug.Log("NO KEY");
return;
}
if (!GetComponent<SavingSystem>().SaveFileExists(GetCurrentSave()))
{
Debug.Log("NO SAVING SYSTEM");
return;
}
StartCoroutine(LoadLastScene());
}
Load Game is
public void LoadGame(string saveFile)
{
SetCurrentSave(saveFile);
ContinueGame();
}
any advice would be appreciated.