Forum begins after the advertisement:
[Part 7] Updating the Map
Home › Forums › Video Game Tutorial Series › Creating a Metroidvania in Unity › [Part 7] Updating the Map
- This topic has 34 replies, 3 voices, and was last updated 2 weeks, 1 day ago by
Nirvik Rajbhandari.
-
AuthorPosts
-
May 29, 2026 at 2:27 am #19704::
The fix for the respawn bug is above it shows the portion in
SceneTransition.csthat need to change to fix, the bug only occurs when the player dies within the same scene as their bench save after walking into said scene from a different scene.As for the player position saving after killing shade, I am not sure if it is meant to work that way but with how it is coded currently I believe so, essentially when shade dies it restore the player mana back to full and save player data, I’m guessing it meant to only save the fullmana bool, but the save function holds all other information to be saved, if you want to fix it make a new function within the
SaveData.csonly for player manastate then replace theSavePlayerData()function within shade death with it.- 1 anonymous person
May 29, 2026 at 8:07 am #19705::that error is gone but Im getting a similar error message to earlier except for the player EndOfStreamException: Unable to read beyond the end of the stream. System.IO.BinaryReader.ReadString () (at <4a4789deb75f446a81a24a1a00bdd3f9>:0) SaveData.LoadPlayerData () (at Assets/Scripts/SaveData.cs:113) PlayerController.Start () (at Assets/Scripts/PlayerController.cs:161)
May 29, 2026 at 10:38 am #19706May 29, 2026 at 12:56 pm #19707::This error occured due to how specific binary works, when you write things in you read them out in the same order, as you removed mana things to be written into binary, when it is being read playerMana and PlayerHalfMana is still expecting and got values from playerposition x&y. If you want the player mana only to be saved after killing shade I have made the function.
SaveData.cspublic void SavePlayerData() { using (BinaryWriter writer = new BinaryWriter(File.OpenWrite(Application.persistentDataPath + "/save.player.data"))) { playerHealth = PlayerController.Instance.Health; playerMana = PlayerController.Instance.Mana; playerHalfMana = PlayerController.Instance.halfMana; playerPosition = PlayerController.Instance.transform.position; lastScene = SceneManager.GetActiveScene().name; writer.Write(playerHealth); writer.Write(playerMana); writer.Write(playerHalfMana); writer.Write(playerPosition.x); writer.Write(playerPosition.y); writer.Write(lastScene); } } public void SavePlayerManaData() { FileInfo playerInfo = new FileInfo(Application.persistentDataPath + "/save.player.data"); if (playerInfo.Exists && playerInfo.Length != 0) { using (BinaryReader reader = new BinaryReader(File.OpenRead(Application.persistentDataPath + "/save.player.data"))) { playerHealth = reader.ReadInt32(); playerMana = reader.ReadSingle(); playerHalfMana = reader.ReadBoolean(); playerPosition.x = reader.ReadSingle(); playerPosition.y = reader.ReadSingle(); lastScene = reader.ReadString(); playerHealth = PlayerController.Instance.Health; playerMana = PlayerController.Instance.Mana; playerHalfMana = PlayerController.Instance.halfMana; } } using (BinaryWriter writer = new BinaryWriter(File.OpenWrite(Application.persistentDataPath + "/save.player.data"))) { writer.Write(playerHealth); writer.Write(playerMana); writer.Write(playerHalfMana); writer.Write(playerPosition.x); writer.Write(playerPosition.y); writer.Write(lastScene); } }then just change the function shade calls on death
Shade.csprotected override void ChangeEnemyAnimation() { if(currentEnemyState == EnemyStates.Shade_Idle) { anim.Play("Player_Idle"); } anim.SetBool("Walking", GetCurrentEnemyState == EnemyStates.Shade_Chase); if (currentEnemyState == EnemyStates.Shade_Stunned) { anim.SetTrigger("TakeDamage"); } if (GetCurrentEnemyState == EnemyStates.Shade_Death) { PlayerController.Instance.RestoreMana(); SaveData.Instance.SavePlayerData(); SaveData.Instance.SavePlayerManaData(); anim.SetTrigger("Death"); Destroy(gameObject, 0.5f); } }also in scene transition can you move the removal of gamemanager transition from, I’m not sure why but only when moving from scene 3 to scene 2, you will stay in the same place causing you to fall from the sky.
SceneTransition.csprivate void Start() { if(GameManager.Instance.transitionedFromScene == transitionTo) { PlayerController.Instance.transform.position = startPoint.position; PlayerController.Instance.pState.cutscene = true; PlayerController.Instance.pState.invincible = true; StartCoroutine(PlayerController.Instance.WalkIntoNewScene(exitDirection, exitTime)); GameManager.Instance.transitionedFromScene = null; } StartCoroutine(UIManager.Instance.sceneFader.Fade(SceneFader.FadeDirection.Out)); GameManager.Instance.transitionedFromScene = null; }- 1 anonymous person
May 29, 2026 at 9:51 pm #19708::I believe it has worked, but its giving me this error and spawning the player in a different spot. Scene ” couldn’t be loaded because it has not been added to the build settings or the AssetBundle has not been loaded. To add a scene to the build settings use the menu File->Build Settings… UnityEngine.SceneManagement.SceneManager:LoadScene (string) SaveData:LoadPlayerData () (at Assets/Scripts/SaveData.cs:146) PlayerController:Start () (at Assets/Scripts/PlayerController.cs:161) Github is updated once again.
May 30, 2026 at 1:27 am #19709::I think your playerdata is corrupted as it is trying to load a scene that with the name ” no scene should no name, go to the location your the save data is stored in your computer and delete them. If it does still exist after deleting save.player.data and running the game, at the top-right of your editor go File > Build Settings, make sure your scene is in the build and checked.
May 30, 2026 at 12:28 pm #19710::Most of it is working now the only problem is that the player spawns in the same scene they killed the shade in but at the coordinates of the last bench they interacted with. Github updated.
May 30, 2026 at 4:05 pm #19711::I am having problem trying to recreate the error you see, are you able to give me a rundown of what you did, start by clearing all save data within your computer then, just a rundown like:
Start running game, go to bench in scene 1, save on bench, go to scene 2, die, respawn on bench at scene 1, go to scene 2, kill shade, stop running game, start running game, see error.
May 30, 2026 at 8:03 pm #19712::I think you summarized it. Say I start in scene 1 with no save, then I go to scene 2 and die, then I kill the shade, stop running the game, and press play again.
May 31, 2026 at 4:20 pm #19714::The error is not caused by the shade, the error happens when you respawn, when you respawn the active scene is still the one you died in so when you called SavePlayerData() you saved the dead scene and not the bench scene. Since you need the scene to change first before saving I notice there was a startcoroutine to deactivate death screen and decided to put it in there.
GameManager.cspublic void RespawnPlayer() { SaveData.Instance.LoadBench(); if (SaveData.Instance.benchSceneName != null) { SceneManager.LoadScene(SaveData.Instance.benchSceneName); Debug.Log("Loaded scene " + SaveData.Instance.benchSceneName); } if(SaveData.Instance.benchPos != null) { respawnPoint = SaveData.Instance.benchPos; } else { respawnPoint = platformingRespawnPoint; } PlayerController.Instance.transform.position = respawnPoint; StartCoroutine(UIManager.Instance.DeactivateDeathScreen()); PlayerController.Instance.Respawn(); }UIManager.cspublic IEnumerator DeactivateDeathScreen() { yield return new WaitForSeconds(0.5f); PlayerController.Instance.Respawn(); deathScreen.SetActive(false); StartCoroutine(sceneFader.Fade(SceneFader.FadeDirection.Out)); }This way the player data is saved after the new scene have loaded in.
May 31, 2026 at 11:38 pm #19725June 2, 2026 at 6:40 am #19733::I dont know if this is related but when I transition specifically from scene 3 to 2 i spawn in from the sky. Github is updated.
June 2, 2026 at 10:10 am #19734::Within the SceneTransition you just need to move transitionfromscene up
SceneTransitionprivate void Start() { if(GameManager.Instance.transitionedFromScene == transitionTo) { PlayerController.Instance.transform.position = startPoint.position; PlayerController.Instance.pState.cutscene = true; PlayerController.Instance.pState.invincible = true; StartCoroutine(PlayerController.Instance.WalkIntoNewScene(exitDirection, exitTime)); GameManager.Instance.transitionedFromScene = null; } StartCoroutine(UIManager.Instance.sceneFader.Fade(SceneFader.FadeDirection.Out)); GameManager.Instance.transitionedFromScene = null; }This is mainly due to Scene 2 havin 2 scenetransition I’ll call transitionA (scene 1-2) and transitionB (scene 2-3), transitionA runs before transitionB due to heirarchy causing it to remove the transitionFromScene causing transitionB f statement to not run causing the player to remain midair all fall out the sky.
June 2, 2026 at 11:08 pm #19744::Nirvik, the older save system has quite a few issues. I suggest you skip bugfixing the save system issues until you reach Part 15, where we implement the newer save system.
June 5, 2026 at 11:52 pm #19755 -
AuthorPosts
- You must be logged in to reply to this topic.
Advertisement below: