When I use ES3.Load<Texture2D>() ,I get :FormatException: Input string was not in a correct format.

Discussion and help for Easy Save 3, The Complete Save Game & Data Serializer System for the Unity Engine
Post Reply
StarNineCat
Posts: 8
Joined: Thu Dec 29, 2022 1:12 pm

When I use ES3.Load<Texture2D>() ,I get :FormatException: Input string was not in a correct format.

Post by StarNineCat »

I have previously saved the player custom images that I created in the runtime

Code: Select all

        
        //Save a picture of custom item data
        foreach(var sel in PresetCubeData.Repository.PresetCustomizedData)
        {
            if(sel.Sprite && sel.Sprite.texture) ES3.Save($"{sel.Key}:texture", sel.Sprite.texture, Path);
        }
        
Then I try to read the images when I load the archive

Code: Select all

            
            foreach (var sel in PresetCubeData.Repository.PresetCustomizedData)
            {
                CustomizedMilkData CMD = sel as CustomizedMilkData;
                if (CMD != null)
                {
                    if (ES3.KeyExists($"{sel.Key}:texture", Path))
                    {
                        Texture2D T = ES3.Load<Texture2D>($"{sel.Key}:texture", Path);
                        CMD.SetSprite(Sprite.Create(T, new Rect(0, 0, T.width, T.height), new Vector2(0.5f, 0.5f), 100));
                	}
                }
            }
            
And then I had an error:

FormatException: Input string was not in a correct format.
System.Number.StringToNumber (System.String str, System.Globalization.NumberStyles options, System.Number+NumberBuffer& number, System.Globalization.NumberFormatInfo info, System.Boolean parseDecimal) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Number.ParseInt32 (System.String s, System.Globalization.NumberStyles style, System.Globalization.NumberFormatInfo info) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Int32.Parse (System.String s) (at <695d1cc93cca45069c528c15c9fdd749>:0)
ES3Internal.ES3JSONReader.Read_int () (at Assets/Plugins/Easy Save 3/Scripts/Readers/ES3JSONReader.cs:549)
ES3Types.ES3Type_int.Read[T] (ES3Reader reader) (at Assets/Plugins/Easy Save 3/Scripts/Types/Primitive Types/ES3Type_int.cs:24)
ES3Reader.Read[T] (ES3Types.ES3Type type) (at Assets/Plugins/Easy Save 3/Scripts/Readers/ES3Reader.cs:276)
ES3Types.ES3Type_Texture2D.ReadUnityObject[T] (ES3Reader reader) (at Assets/Plugins/Easy Save 3/Scripts/Types/Unity Types/ES3Type_Texture2D.cs:105)
ES3Types.ES3UnityObjectType.ReadObject[T] (ES3Reader reader) (at Assets/Plugins/Easy Save 3/Scripts/Types/ES3UnityObjectType.cs:71)
ES3Types.ES3ObjectType.Read[T] (ES3Reader reader) (at Assets/Plugins/Easy Save 3/Scripts/Types/ES3ObjectType.cs:52)
ES3Reader.ReadObject[T] (ES3Types.ES3Type type) (at Assets/Plugins/Easy Save 3/Scripts/Readers/ES3Reader.cs:253)
ES3Reader.Read[T] (ES3Types.ES3Type type) (at Assets/Plugins/Easy Save 3/Scripts/Readers/ES3Reader.cs:282)
ES3Reader.Read[T] (System.String key) (at Assets/Plugins/Easy Save 3/Scripts/Readers/ES3Reader.cs:201)
ES3.Load[T] (System.String key, ES3Settings settings) (at Assets/Plugins/Easy Save 3/Scripts/ES3.cs:443)
ES3.Load[T] (System.String key, System.String filePath) (at Assets/Plugins/Easy Save 3/Scripts/ES3.cs:417)
SaveAndLoad.Load (System.String SaveName) (at Assets/Script/SaveAndLoad/SaveAndLoad.cs:249)

I don't know what I did wrong
User avatar
Joel
Moodkie Staff
Posts: 5048
Joined: Wed Nov 07, 2012 10:32 pm

Re: When I use ES3.Load<Texture2D>() ,I get :FormatException: Input string was not in a correct format.

Post by Joel »

Hi there,

I've not seen anything like this before, though my best guess is that the text encoding of the file is different to the one being loaded. This is most commonly because the file has been manually modified in a text editor and saved using an encoding other than UTF8. In this case deleting the save data (by going to Tools > Easy Save 3 > Clear Persistent Data Path) and ensuring the file is only saved with UTF8 encoding after being manually modified would resolve the issue.

If this isn't the case for you, please could you replicate this in a new project with a simple scene and send it to me using the form at moodkie.com/repro.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
StarNineCat
Posts: 8
Joined: Thu Dec 29, 2022 1:12 pm

Re: When I use ES3.Load<Texture2D>() ,I get :FormatException: Input string was not in a correct format.

Post by StarNineCat »

I have two scenarios: StartLevel and MainLevel. The MainLevel scene is automatically loaded when the archive is loaded. This Bug occurs when I load the archive from StartLevel. Everything works fine when I load the archive from MainLevel.
Then I realized that I hadn't added the Easy Save 3 Manager in StartLevel.
Post Reply