Forum begins after the advertisement:


[Part 7] Updating the Map

Viewing 8 posts - 21 through 28 (of 28 total)
  • Author
    Posts
  • #19704
    Sean Ng
    Level 7
    Moderator
    Helpful?
    Up
    1
    ::

    The fix for the respawn bug is above it shows the portion in SceneTransition.cs that 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.cs only for player manastate then replace the SavePlayerData() function within shade death with it.

      1 anonymous person
    has upvoted this post.
    #19705
    Nirvik Rajbhandari
    Level 6
    Participant
    Helpful?
    Up
    0
    ::

    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)

    #19706
    Nirvik Rajbhandari
    Level 6
    Participant
    Helpful?
    Up
    0
    ::

    github is updated

    #19707
    Sean Ng
    Level 7
    Moderator
    Helpful?
    Up
    1
    ::

    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.cs

    public 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.cs

    
        protected 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.cs

    private 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
    has upvoted this post.
    #19708
    Nirvik Rajbhandari
    Level 6
    Participant
    Helpful?
    Up
    0
    ::

    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.

    #19709
    Sean Ng
    Level 7
    Moderator
    Helpful?
    Up
    0
    ::

    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.

    #19710
    Nirvik Rajbhandari
    Level 6
    Participant
    Helpful?
    Up
    0
    ::

    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.

    #19711
    Sean Ng
    Level 7
    Moderator
    Helpful?
    Up
    0
    ::

    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.

Viewing 8 posts - 21 through 28 (of 28 total)
  • You must be logged in to reply to this topic.

Go to Login Page →


Advertisement below: