Forum begins after the advertisement:
[part 7] 9 minute error wont go
Home › Forums › Video Game Tutorial Series › Creating a Metroidvania in Unity › [part 7] 9 minute error wont go
- This topic has 5 replies, 2 voices, and was last updated 8 months, 3 weeks ago by
Terence.
-
AuthorPosts
-
December 19, 2023 at 4:09 am #12708
Niyam Shah
Participant::at 9 minutes in the video shows an error – it says to save your game in the bench and restart to fix it – ive tried this for 10 minuted and the error persists. My error is identical to the videos so not sure if he did anything different – i even restarted unity to see if it worked?
December 19, 2023 at 8:37 am #12709Niyam Shah
Participant::This feature worked for all the other save data bits – even when i remove the wall jumping bits from the save data script, the console will throw the same error – not sure what happened
December 19, 2023 at 8:41 am #12710Niyam Shah
Participant::The DebugLog – “worked” doesnt play – neither does the “file doesnt exist”
using System.Collections; using System.Collections.Generic; using UnityEngine; using System.IO; using UnityEngine.SceneManagement; [System.Serializable] public struct SaveData { public static SaveData Instance; //maps public HashSet<string> sceneNames; //savePoints public string savePointSceneName; public Vector2 savePointPos; //player public int playerHealth; public float playerMana; public Vector2 playerPosition; public string lastScene; public bool playerUnlockedWallJump; public void Initialize() { if(!File.Exists(Application.persistentDataPath + "/save.savePoint.data")) { BinaryWriter writer = new BinaryWriter(File.Create(Application.persistentDataPath + "/save.savePoint.data")); } if (!File.Exists(Application.persistentDataPath + "/save.player.data")) { BinaryWriter writer = new BinaryWriter(File.Create(Application.persistentDataPath + "/save.player.data")); } if (sceneNames == null) { sceneNames = new HashSet<string>(); } } public void SaveSavePoint() { using (BinaryWriter writer = new BinaryWriter(File.OpenWrite(Application.persistentDataPath + "/save.savePoint.data"))) { writer.Write(savePointSceneName); writer.Write(savePointPos.x); writer.Write(savePointPos.y); } } public void LoadSavePoint() { if (!File.Exists(Application.persistentDataPath + "/save.savePoint.data")) { using(BinaryReader reader = new BinaryReader(File.OpenRead(Application.persistentDataPath + "/save.savePoint.data"))) { savePointSceneName = reader.ReadString(); savePointPos.x = reader.ReadSingle(); savePointPos.y = reader.ReadSingle(); } } } public void SavePlayerData() { using (BinaryWriter writer = new BinaryWriter(File.OpenWrite(Application.persistentDataPath + "/save.player.data"))) { playerHealth = PlayerController.Instance.Health; writer.Write(playerHealth); playerMana = PlayerController.Instance.Mana; writer.Write(playerMana); playerUnlockedWallJump = PlayerController.Instance.unlockWallJump; writer.Write(playerUnlockedWallJump); playerPosition = PlayerController.Instance.transform.position; writer.Write(playerPosition.x); writer.Write(playerPosition.y); lastScene = SceneManager.GetActiveScene().name; writer.Write(lastScene); } } public void LoadPlayerData() { if(File.Exists(Application.persistentDataPath + "/save.player.data")) { using (BinaryReader reader = new BinaryReader(File.OpenRead(Application.persistentDataPath + "/save.player.data"))) { playerHealth = reader.ReadInt32(); playerMana = reader.ReadSingle(); playerPosition.x = reader.ReadSingle(); playerPosition.y = reader.ReadSingle(); lastScene = reader.ReadString(); playerUnlockedWallJump = reader.ReadBoolean(); SceneManager.LoadScene(lastScene); PlayerController.Instance.transform.position = playerPosition; PlayerController.Instance.Health = playerHealth; PlayerController.Instance.Mana = playerMana; PlayerController.Instance.unlockWallJump = playerUnlockedWallJump; Debug.Log("worked"); } } else { Debug.Log("file doesnt exist"); PlayerController.Instance.Health = PlayerController.Instance.maxHealth; PlayerController.Instance.Mana = 0.5f; PlayerController.Instance.unlockWallJump = false; } } }
December 20, 2023 at 10:03 pm #12713Terence
Keymaster::Only thing I can tell you here is that if the Debug.Log doesn’t play, it means that
LoadPlayerData()
is not firing at all.December 20, 2023 at 11:19 pm #12716Niyam Shah
Participant::ah yes i figured this out yesterday – it was a formatting issue:
had to keep my writer and readers for transforming player position and loading scene at the bottom – not before anything else
December 21, 2023 at 5:20 pm #12723 -
AuthorPosts
- You must be logged in to reply to this topic.
Advertisement below: