Page 1 of 1

Extensive Documentation for Save System

Posted: Tue Mar 18, 2025 1:03 am
by LostContinentGames
Hello,

I'm wondering where I can find extensive documentation for the Save System.

The documentation here is a pretty basic overview:
https://www.pixelcrushers.com/dialogue_ ... ystem.html

The YouTube tutorial is also pretty narrow.

I found your guide on custom savers here to be very helpful:
https://pixelcrushers.com/phpbb/viewtop ... f=9&t=4763

However, I have a lot of questions, and I'd like to know where I can find answers. For instance, if something is saved with a custom saver, how is it then loaded?

If I'm on the main menu load screen, how do I display relevant information from each save slot (example: location, characters unlocked, money, etc.)?

If there's a centralized place to find all this info or a collection of helpful posts you have, I would really appreciate it.

Thank you.

Re: Extensive Documentation for Save System

Posted: Tue Mar 18, 2025 1:50 pm
by Tony Li
Hi,

This article is a guide on showing saved game summary info in a main menu / load game screen:
How To: Include Summary Info In Saved Games

You can also find a full guide in Assets / Plugins / Pixel Crushers / Common / Documentation / Save_System_Manual.pdf

And if you have any questions after that, please don't hesitate to ask here. I'm here to help!

Re: Extensive Documentation for Save System

Posted: Thu Mar 20, 2025 1:16 am
by LostContinentGames
Thank you. This is really helpful. I understand everything in that link except for the image saving process.

For me, I don't want to save a screenshot. I'd prefer to save a custom image/sprite. I would place the sprite on each save point, so it would be saved from there.

I'm not really understanding the conversion process.

It looks like to convert the image to the byte[], I need a Texture2D, not a sprite. So, I need to change the sprite into a Texture2D, and then convert it to byte[] via ImageConverstion.EncodeToPNG() ?

Then, I need to load it with ImageConversion.LoadImage(), but that only returns a bool? If it did return the texture, how would I convert that into a sprite that could be displayed on screen?

Is this process only for screenshots-- could I just save a sprite by adding a Sprite variable to the SaveData class?

Re: Extensive Documentation for Save System

Posted: Thu Mar 20, 2025 1:52 am
by Tony Li
Hi,

A Sprite object is basically just a wrapper around a Texture object. To access the Sprite's texture, use Sprite.texture. Then you can save the texture to a PNG or convert it to a byte[] array. Going the other direction, if you have a texture, you can use Sprite.CreateCreate() to create a Sprite from a texture.

Re: Extensive Documentation for Save System

Posted: Thu Mar 20, 2025 3:19 am
by LostContinentGames

Code: Select all


public Sprite spriteToSave;


    [Serializable]
    public class SaveData
    {

        public Texture2D texture2D;
        
    }

    public override string RecordData()
    {
        
        var data = new SaveData();

        data.texture2D= spriteToSave.texture;


        return SaveSystem.Serialize(data);
    }

    public override void ApplyData(string s)
    {
        
	spriteToSave = Sprite.CreateCreate(data.texture2D);

    }


Okay, so is this correct?

Re: Extensive Documentation for Save System

Posted: Thu Mar 20, 2025 11:44 am
by Tony Li
Hi,

By default, the save system uses Unity's built-in JsonUtility to serialize its save data. JsonUtility cannot directly serialize a Texture2D. You'll need to get the raw byte[] array from the Texture2D. An easy way to do this is to use Unity's ImageConversion class to convert the image to a PNG. In RecordData(), use ImageConversion.EncodeToPNG() to convert the sprite's Texture to a PNG byte[] array, which you can then assign to your Data object. In ApplyData(), use ImageConversion.LoadImage() to turn the byte[] array back into a Texture, which you can then pass to Sprite.CreateSprite() to recreate the sprite.

Re: Extensive Documentation for Save System

Posted: Thu Mar 20, 2025 11:11 pm
by LostContinentGames
Thank you for the extensive instruction!

I finally got it to work.

Re: Extensive Documentation for Save System

Posted: Thu Mar 20, 2025 11:12 pm
by Tony Li
Happy to help! Glad you got it working.