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 27 replies, 3 voices, and was last updated 53 minutes ago by
Sean Ng.
-
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.
-
AuthorPosts
- You must be logged in to reply to this topic.
Advertisement below: