Hi everyone, I’ve been going through the RPG course and whilst in the ‘Character Stats’ section, my saving/loading functionality started to forget the exp and levels that my character gained. I’m not sure exactly when this started happening as it was working at the start, but there were some lectures that were making small tweaks to the code halfway through and when I had a thorough test of the progress halfway through the section, this is when I noticed the problem.
I actually refrained from posting the problem earlier as the last time I came across a bug, I was informed that the issue I encountered at that time was solved in a later section. I’ve now reached the end of the course and for the most part everything else is working fine for me to continue to the next courses, except this saving/loading problem which is a big game-breaker.
I’ve enclosed a couple of pictures that outlines what happens when playing, but to briefly describe it anyway: My character will gain exp and level as normal, and I can save as per normal, but as soon as I load the game or if I teleport to another scene, the level and exp gets reset. I remain with the current health points, but my max health gets reset.
I’m using Unity version 2020.3.10f. I’m not sure if this may have something to do with the issue or not, but in this version, the layout of Scriptable objects was slightly different then what was shown in the video lectures, and it wasn’t possible for me to write character stats in Visual Code script, meaning I had to manually input them in Inspector. It may not have any baring on the problem I’m experiencing, but I feel I needed to mention it, incase this disconnect is in fact an issue with this version of Unity?
This is how the layout of the Scriptable Objects appear in this version of Unity.
I’ve also enclosed my SavingWrapper.cs script below just incase this may be where the issue lays. Any help would be really appreciated, as I feel I can’t move onto one of the sister RPG courses with my project until this is working (unless this is actually an issue that is addressed in one of the other courses?)
SavingWrapper.cs
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using RPG.Saving;namespace RPG.SceneManagement
{
public class SavingWrapper : MonoBehaviour
{
const string defaultSaveFile = “save”;
[SerializeField] float fadeInTime = 0.2f;void Awake() { StartCoroutine(LoadLastScene()); } private IEnumerator LoadLastScene() { //Debug.Log("SavingWrapper LoadLastScene() executed"); yield return GetComponent<SavingSystem>().LoadLastScene(defaultSaveFile); Fader fader = FindObjectOfType<Fader>(); fader.FadeOutImmediate(); yield return fader.FadeIn(fadeInTime); } void Update() { if (Input.GetKeyDown(KeyCode.L)) { Load(); } if (Input.GetKeyDown(KeyCode.S)) { Save(); } if (Input.GetKeyDown(KeyCode.Delete)) { Delete(); } } public void Save() { GetComponent<SavingSystem>().Save(defaultSaveFile); } public void Load() { GetComponent<SavingSystem>().Load(defaultSaveFile); } public void Delete() { GetComponent<SavingSystem>().Delete(defaultSaveFile); } }
}