Saving & Loading Texture2D does nothing.

Discussion and help for Easy Save 3
Post Reply
User avatar
frezno
Posts: 10
Joined: Mon Nov 13, 2017 8:53 pm

Saving & Loading Texture2D does nothing.

Post by frezno »

Hello again Moodkie, back again with another problem.

Previously in Easy Save 2 I was able to save a Texture2D directly to a file using ES2.Save<Texture2D>.

I just got around to converting this old code to Easy Save 3 and everything works except saving and loading the Texture2D.

I use ES3File now to cache my data, so using ES3File.Save<Texture2D> doesn't fail or throw an error, but when checking the file, it seems to have saved nothing. The JSON entry is completely blank. Simple code to test this below.

Code: Select all

    [Header("Original")]
    public Texture2D picture;
    public string data1 = "This is data1";
    public int data2 = 0202383;

    [Header("Load Testing")]
    public Texture2D picture_load=null;
    public string data1_load = "";
    public int data2_load = ;

    /// <summary>
    /// Will update the local file with the data.
    /// </summary>
    void UpdateFile()
    {

        ES3File FileToUpdate = new ES3File("File.es3");

        FileToUpdate.Save<string>("Data-1", data1);
        FileToUpdate.Save<int>("Data-2", data2);
        FileToUpdate.Save<Texture2D>("Picture", picture);

        FileToUpdate.Sync();

    }

    /// <summary>
    /// Will load the data from a local file.
    /// </summary>
    void LoadFile()
    {
        ES3File FileLoad = new ES3File("File.es3");

        picture_load = FileLoad.Load<Texture2D>("Picture"); //Returns nothing, KeyExist is true because the key is in the file, but no data exists for the file.
        data1_load = FileLoad.Load<string>("Data-1"); //Returns fine
        data2_load = FileLoad.Load<int>("Data-2"); //Returns fine
    }
I'm not sure if I'm doing something wrong with this, but iut worked fine with ES2, maybe just an internal problem? Anyways as a workaround for the meantime, I attempted to save the byte[] of the picture using ES3File.Save<byte[]>("Picture", picture.GetRawImageData()) , and everytime I try to load it back with ES3File.Load<byte[]>("Picture") I get an Invalid Length error from ES3File on line 218. I can fix this by converting the byte array to Base64 myself and saving and loading as a string. Just thought you should know this. I can test some if need be.

Thanks.
cloudweight
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Saving & Loading Texture2D does nothing.

Post by Joel »

Hi there,

I don't appear to be having any issues with your code at my end. Please could you PM me a basic project to replicate it?

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
User avatar
frezno
Posts: 10
Joined: Mon Nov 13, 2017 8:53 pm

Re: Saving & Loading Texture2D does nothing.

Post by frezno »

Joel wrote:Hi there,

I don't appear to be having any issues with your code at my end. Please could you PM me a basic project to replicate it?

All the best,
Joel

Hi Joel,

My project is rather large and is also a commercial product, so I can't provide it to you, but I'll try and put together a sample project and seeing if it behaves the same before sending it to you. I was thinking, are you using the version from the Asset Store? Maybe there is a change you made in your "behind the scenes" version that may have fixed this problem. I can't think of anything else that might make this behavior happen. I'll get back to you soon. :)
cloudweight
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Saving & Loading Texture2D does nothing.

Post by Joel »

Hi there,

I was indeed using the version from the Asset Store. However, I'll PM you over the current in-development version at our end just in case it fixes your issue for any other reason.

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