Saving not working ?

Hi

After updating to 5.5.0 version, my save script did not work !! No error at all but not loading game save file ?
I checked docu page, nothing about “file.create” ?!

using UnityEngine;
using System.Collections;
using System;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
using UnityEngine.UI;

public class saveload : MonoBehaviour {

    private gamethings dr;

    void Awake()
    {
        dr = GameObject.FindObjectOfType<gamethings>();
    }
      
    void Start () {
    Load_game_end();

    }
      
    public void Save_game_end()
    {
        BinaryFormatter bf = new BinaryFormatter();
        FileStream data_file = File.Create(Application.persistentDataPath + "/Gworlds.datt");
        eat_things data = new eat_things();
        data.level1t = dr.level1t;

        bf.Serialize(data_file, data);
        data_file.Close();
        Debug.Log("Game full saved");

    }

    public void Load_game_end()
    {
        if (File.Exists (Application.persistentDataPath + "/Gworlds.datt"))
             {
            BinaryFormatter bf = new BinaryFormatter();
            FileStream data_file = File.Open (Application.persistentDataPath + "/Gworlds.datt", FileMode.Open);
            eat_things data = (eat_things)bf.Deserialize(data_file);
            data_file.Close();
            dr.level1t= data.level1t;
            Debug.Log("Game full loaded");
             }

        else{
            Debug.Log("save not found");
              }
    }

    public void delete_save_file() {
        File.Delete(Application.persistentDataPath +"/Gworlds.datt");
    }
  
        [Serializable]
    class eat_things
        public float level1t;
    }
  
    }

So, where is the problem ?

Just to verify, you say it’s not loading but you mention the file.create. So it’s not saving also or it’s not loading but it is saving?

@Quast and @Brathnann - I’m not that well into saving and loading, still learning it, but I don’t even see binaryformatter using .serialize in save game end method? Also, if talk is about loading instead of saving, then I don’t know what the questions means.

bf.serialize(data_file ,data);

When i save i can see the debug message. which mean it “saving”. the same with loading message. but i get nothing ! I guess, my problem is with saving.[quote=“eses, post:3, topic: 650279, username:eses”]
@Lavendn and @Brathnann - I’m not that well into saving and loading, still learning it, but I don’t even see binaryformatter using .serialize in save game end method? Also, if talk is about loading instead of saving, then I don’t know what the questions means.
[/quote]
I don’t know where the problem is. with saving or loading. both was working.

oh, i didn’t copy this lines. sorry.

1 Like