Save File seems to get corrupted after game gets compressed into a zip folder.

Hello, I am actually not sure what subforum I should be posting this topic on, so please correct me if I didn’t put this post in the right place.

For some reason, when I compress my unity game into a zip folder uploading on Itch.io and downloading it off that site to test if the game works, my game is either no longer able to save or load data for some reason, before the game is compressed the save system works fine, so I believe it has something to do with compressing the game and downloading another version of it into my desktop.

I am using JSON to for the data in my game. In the Editor when I save the game I could see the data change from the inspector, but as soon as I leave the scene and load the data, it all disappears.

I thought it was the issue with the directory and filename, but after changing the names, the problem still persists. The only way I can get it working again is to delete the entire project and download a different version of the game project from my USB drive, but if I were to compress it again, the same problem happens.

Are you getting any errors messages? Anything in the Player.log?

How are you reading/writing the file too?

Though by the sounds of it, do you have the sale file packaged with the game itself? Would be better to use Application.persistantDataPath to as the location for any save files.

Yes I am getting variations of these fail to insert item messages:
Failed to insert item.
Name: Yes No set Active, Command: SCRIPT7722

Failed to insert item.
Name: Zombie Astronaut, Command: SCRIPT6426
(There are a ton of these but I have no idea what they are)

And This Error:
NullReferenceException: Object not set up to an instance of an object
Unity.Cloud.Collaborate.UserInterface.CollaborateWindow.OnDisable()
(at Library/PackageCache/com.unity.collab-proxy@1.5.7/Editor/Colaborate/
UserInterface/CollaborateWindow.cs:86)

Here is how I written my JSON file:

using UnityEngine;
using System.IO;
using System;

public static class JsonSaveManager
{
    public static string directory = "/SaveData02/";
    public static string fileName = "MyData02.txt";

    public static void Save(SaveHealth so)
    {
        string dir = Application.persistentDataPath + directory;

        if (!Directory.Exists(dir))
            Directory.CreateDirectory(dir);

        string json = JsonUtility.ToJson(so);
        File.WriteAllText(dir + fileName, json);
    }

    public static SaveHealth Load()
    {
        string fullPath = Application.persistentDataPath + directory + fileName;
        SaveHealth so = new SaveHealth();

        if (File.Exists(fullPath))
        {
            string json = File.ReadAllText(fullPath);
            so = JsonUtility.FromJson<SaveHealth>(json);
            Levelloader.loadsave = true;
          //  SoundManager.PlaySound("SelectionSound");
        }
        else
        {
            NoDataScript.noData = true;
        }

        return so;

    }

    public static SaveHealth Delete()
    {
         string fullPath = Application.persistentDataPath + directory + fileName;
        SaveHealth so = new SaveHealth();
        if (File.Exists(fullPath))
        {

        //    SoundManager.PlaySound("SelectionSound");
            File.Delete(fullPath);
        }
        else
        {
            NoDataScript.noData = true;
           
        }
        return so;
    }

}

Is that happening a build or in the editor?

Both errors look like editor errors. Nothing to do with corrupted files.

The first error comes up a bunch if you google it: Failed to insert item messages in build log

What Unity version are you on? Looks like it was fixed a while ago.

The second error might also be fixed up updating editor versions.

It basically happens to both, after the files get compressed and I think after the game in zip form is downloaded from Itch.IO, something gets messed up. But before the game gets compressed, both the editor and the build works fine.

Edit: The version I’m using is 2020.3.11f1, and would changing to newer versions still corrupt your entire project? I tried this on an older project before, and I basically have to move all the assets to a completely new file to fix all the errors.
Edit2: In case if a solution can’t be found, do you know of anything I can read or research into to try to find the problem myself?

That’s for you to test. Updating project within the same major and minor version shouldn’t corrupt anything. You’re behind on a lot of revision updates for the 2020 LTS version.

I would hope you’re using version control.

Also not sure why you would compress an unbuilt game.

I mean you can Google the errors like I did. The first error is a windows thing supposedly fixed in recent LTS versions.

Okay, I will just update to the newer version so see if the problem still persists. What happens if I don’t use version control?

And actually I only compressed the built game, however it still effects both the game in the build and the Editor because they share the same file and directory.

I’ll see what can find on google, I had trouble before because as you mention I wasn’t sure if the errors are causing it or if its an installation problem that causes file corruption.

You’re putting your project at risk of being irrepairable with no way to easily revert these changes.

I’ll go check out what that is, thanks.

For now, I will just keep the version of the game with the functional save system in my USB drive and try to figure out what is wrong with the current ones on my desktop.