Hello @sampattuzzi I came back after one month or so and I’ve seen a lot of update on the course, so I check all the lesson left white from before and I went little in confusion when I’ve seen you make a different section for the saving system and allow it as a separate download. I’d already pass all the course so I not import it and went to the other lessons until here. So I check the respawn stuff and the resource folder and the first error I got was about the namespace, I had Health class on the namespace Resources so I could not use your code, so, I not know if I did it right but I changed the namespace of health script as RPG.Core and did all this for all the scripts being called. Ok that’s one stuff, the other problem come up as long as I implement the saving system of the weapon and the respawn. I did a test just for fun of passing a portal without any weapon on hand and I got the error:
NullReferenceException: Object reference not set to an instance of an object
RPG.Combat.Fighter.CaptureState () (at Assets/Scripts/Combat/Fighter.cs:136)
RPG.Saving.SaveableEntity.CaptureState () (at Assets/Scripts/Saving/SaveableEntity.cs:28)
RPG.Saving.SavingSystem.CaptureState (System.Collections.Generic.Dictionary`2[TKey,TValue] state) (at Assets/Scripts/Saving/SavingSystem.cs:82)
RPG.Saving.SavingSystem.Save (System.String saveFile) (at Assets/Scripts/Saving/SavingSystem.cs:32)
RPG.SceneManagement.SavingWrapper.Save () (at Assets/Scripts/SceneManagement/SavingWrapper.cs:43)
RPG.SceneManagement.Portal+<Transition>d__8.MoveNext () (at Assets/Scripts/SceneManagement/Portal.cs:64)
UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at C:/buildslave/unity/build/Runtime/Export/Coroutines.cs:17)
the error apperas on this call in fighter.cs script during saving between portals
public object CaptureState()
{
return currentWeapon.name;
}
Ok so I did little investigation on the Portal script and did little debug.log as follow:
private IEnumerator Transition()
{
if (sceneToLoad < 0)
{
Debug.LogError("Scene to load not set !");
yield break;
}
DontDestroyOnLoad(gameObject);
Fader fader = FindObjectOfType<Fader>();
SavingWrapper savingWrapper = FindObjectOfType<SavingWrapper>();
yield return fader.FadeOut(fadeOutTime);
//Before the saveing of Player position, I reset it to the spawn point of the portal for prevent infinite loop
Debug.Log("before portal save");
savingWrapper.Save();
yield return SceneManager.LoadSceneAsync(sceneToLoad);
Debug.Log("before portal load");
savingWrapper.Load();
Debug.Log("after portal load");
Portal otherPortal = GetOtherPortal();
UpdatePlayer(otherPortal);
Debug.Log("before portal save again");
//// HERE IS THE ISSUE
savingWrapper.Save();
Debug.Log("after portal save again");
yield return new WaitForSeconds(fadeWaitTime);
yield return fader.FadeIn(fadeInTime);
GameObject.FindWithTag("Player").GetComponent<PlayerController>().enabled = true;
Destroy(gameObject);
}
I did not see the message after the portal save again, and I manage to solve it only by moving the last save instruction after the first yield return new WaitForSeconds(fadeWaitTime);
I suspect it has something to do with the weapons not loaded properly on the change of the scene or not initialized properly ?
If I stop execution of Unity after the crash and then reload the last scene it work properly even on the scene switch even without the fix but not understand really well why this happen and if only happen to me.
Last question is, why we never save the rotation ? in mover we saving only the position right ? But when reload the last checkpoint and player is facing another direction it’s look kinda weird.
Sorry for long question but I hope you could help me out. And maybe that this help someone others, and thank you for your amazing work.