FormatException: Expected '{' or "null", found ','.

Discussion and help for Easy Save 3
Post Reply
epicmcdude
Posts: 4
Joined: Sat Aug 03, 2024 4:05 pm

FormatException: Expected '{' or "null", found ','.

Post by epicmcdude »

Hello,

This error happened to for the first time today and I've searched on this forum that a fix is to delete the save data, but I wanted to know if it's possible to fix this error without deleting the save file? Just so players don't have to delete their save file if this happens in a full release. I've a player report this to me and I didn't know how to replicate but now it's happening to me every time I load a test scene.

I'm saving and loading a list of gameobjects that I add/remove at runtime.

I'm also using the PrefabManager example script, with the following methods to save/load:

Code: Select all

 
 
 private void Start()
{
    prefabInstances = new List<GameObject>();
}
 
 public void SavePrefabInstances()
 {

     // Save our prefabInstances list to file using "prefabInstances" as the unique key to identify the data.

     if (IsQuicksave)
     {
         ES3.Save(PrefabsKey, prefabInstances, "SAVES/filepath");
     }

     else
     {
         ES3.Save(PrefabsKey, prefabInstances, "SAVES/autofilepath");

     }
 }
 
 public void LoadPrefabInstances()
{

    if (IsQuicksave)
    {
        prefabInstances = ES3.Load(PrefabsKey, "SAVES/filepath", new List<GameObject>());
    }

    else
    {
        prefabInstances = ES3.Load(PrefabsKey, "SAVES/autofilepath", new List<GameObject>());
    }
}
 
 
User avatar
Joel
Moodkie Staff
Posts: 4973
Joined: Wed Nov 07, 2012 10:32 pm

Re: FormatException: Expected '{' or "null", found ','.

Post by Joel »

Hi there,

Generally it's not possible to recover from this because it indicates that the save data is corrupt. You can find more info about this error in the Error Handling guide (see https://docs.moodkie.com/easy-save-3/es ... -handling/).

However, if this is happening consistently (i.e. not because something external to Easy Save such as the OS or anti-virus) then you will want to understand why it is happening before releasing as it usually indicates that you're saving data which isn't serializable at runtime. If you're able to replicate this in a new project with a simple scene then I'm happy to take a look if you send it to me on moodkie.com/contact along with step-by-step instructions.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
epicmcdude
Posts: 4
Joined: Sat Aug 03, 2024 4:05 pm

Re: FormatException: Expected '{' or "null", found ','.

Post by epicmcdude »

This error happens when I instantiate an object and parent it to another object in the scene. I save the file and then load and that errors shows up. When loading, the object also spawns with the saved position/rotation values except it's world position instead of local (because no parent).

Checking the types supported https://docs.moodkie.com/easy-save-3/es ... rted-types and the transform should be saving the parent.

I've been able to reproduce this on an empty project -
In play mode, drag a Prefab onto an empty transform, we'll call it Parent Object, or instantiate it and parent it to Parent Object in that scene.
Save the instantiated or dragged prefab into a list, just like I'm doing below
Then Change Scene and then go back to that same scene
Load the list and the prefab gets properly instantiated but immediately gets unparented and it throws out the error.


///


However,I'm now having another error because I tried adding another list to the Prefab Manager script:
InvalidOperationException: Trying to load data of type System.Collections.Generic.List`1[UnityEngine.GameObject], but data contained in file is type of System.String.
ES3Reader.ReadTypeFromHeader[T] () (at Assets/Plugins/Easy Save 3/Scripts/Readers/ES3Reader.cs:314)
ES3Reader.Read[T] (System.String key, T defaultValue) (at Assets/Plugins/Easy Save 3/Scripts/Readers/ES3Reader.cs:215)
ES3.Load[T] (System.String key, T defaultValue, ES3Settings settings) (at Assets/Plugins/Easy Save 3/Scripts/ES3.cs:510)
ES3.Load[T] (System.String key, System.String filePath, T defaultValue) (at Assets/Plugins/Easy Save 3/Scripts/ES3.cs:482)
SaveAndLoadPrefabsInstantiatedAtRuntime.PrefabManager.LoadPrefabInstances () (at Assets/Easy Save 3/Examples/Save and Load Prefabs Instantiated at Runtime using Code/PrefabManager.cs:136)
I copied all the lines from the prefabInstances list and replaced with the new inventoryInstances list, so the script is the same except for the new lines for ES3.Save and Load.

Code: Select all

else
{
    prefabInstances = ES3.Load(PrefabsKey, "SAVES/autofilepath", new List<GameObject>());
    inventoryInstances = ES3.Load(InventoryKey, "SAVES/autofilepath", new List<GameObject>());
}
EDIT: I found this topic https://moodkie.com/forum/viewtopic.php?t=2740 and the last post made me try hardcoding the Key value, because I'm building a string to have different keys and it worked... The error stopped showing as soon as I tried writing a string straight into the field.
But I can't use this as a solution because I need to have different keys depending on which scene the Player is in, so I'll always have to build a string to make a key...
User avatar
Joel
Moodkie Staff
Posts: 4973
Joined: Wed Nov 07, 2012 10:32 pm

Re: FormatException: Expected '{' or "null", found ','.

Post by Joel »

Hi there,
EDIT: I found this topic https://moodkie.com/forum/viewtopic.php?t=2740 and the last post made me try hardcoding the Key value, because I'm building a string to have different keys and it worked... The error stopped showing as soon as I tried writing a string straight into the field.
But I can't use this as a solution because I need to have different keys depending on which scene the Player is in, so I'll always have to build a string to make a key...
I've not seen this before either, and to my knowledge a hardcoded key shouldn't be an issue unless your key is null or you're providing the wrong key for the data you're loading. Please could you replicate this and send it to me on moodkie.com/contact with step by step instructions?

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Post Reply