Save System Menu?

Announcements, support questions, and discussion for the Dialogue System.
User avatar
Tony Li
Posts: 21080
Joined: Thu Jul 18, 2013 1:27 pm

Re: Save System Menu?

Post by Tony Li »

No bother at all! And it's much simpler than that. Just add a DiskSavedGameDataStorer to the same GameObject that has the SaveSystem component. When you call SaveSystem.SaveToSlot(#) or use SaveSystemMethods.SaveToSlot(#), the SaveSystem component will automatically detect the DiskSavedGameDataStorer and save the game to disk.
timbecile
Posts: 110
Joined: Mon Mar 12, 2018 11:00 pm

Re: Save System Menu?

Post by timbecile »

Thanks Tony!

I've got it working for the most part, except for the screenshot. I used the position saver as an example and put a class together that had two strings and a sprite (title, description, and screenshot). Everything works except the sprite.

On the save it seems to serialize, but when I go to load it, after deserialization it says it's null. In the saved data the data shows as {"instanceID": -12332066} not sure if that's what it's supposed to do as the strings have readable data.
User avatar
Tony Li
Posts: 21080
Joined: Thu Jul 18, 2013 1:27 pm

Re: Save System Menu?

Post by Tony Li »

Hi,

Unity doesn't serialize asset files such as sprites. You could serialize the sprite's name, or put all of the relevant sprites in an array and serialize the sprite's index in the array.

If the sprite is meant to be a screenshot of the game, a Saver component probably isn't the best solution. Saver components put data inside the saved game. The screenshot is kind of like meta data that sits next to the saved game.

To save the screenshot, you could call ScreenCapture.CaptureScreenshotAsTexture() to get a Texture2D, and then call ImageConversion.EncodeToPNG(). This will give you a byte array that you can write to a file (tutorial).
timbecile
Posts: 110
Joined: Mon Mar 12, 2018 11:00 pm

Re: Save System Menu?

Post by timbecile »

Thanks Tony! That's good to know!

I'll give it a try that way.

I'm going to have a few more questions about saving across level loads , but I'll hold off for now!
User avatar
Tony Li
Posts: 21080
Joined: Thu Jul 18, 2013 1:27 pm

Re: Save System Menu?

Post by Tony Li »

Okay. BTW, use SaveSystem.LoadScene() to save across level loads. This works like Unity's SceneManager.LoadScene() with three additions:

1. It will use the SaveSystem's SceneTransitionManager component if present (e.g., fade out & back in, or show a loading screen).

2. It will save the old scene before leaving, and then apply saved data to the new scene after entering.

3. You can specify a spawnpoint to place the player upon entering the new scene.
timbecile
Posts: 110
Joined: Mon Mar 12, 2018 11:00 pm

Re: Save System Menu?

Post by timbecile »

and that will save and reload scene-specific data? (like a shop inventory, for instance)?
User avatar
Tony Li
Posts: 21080
Joined: Thu Jul 18, 2013 1:27 pm

Re: Save System Menu?

Post by Tony Li »

If that info has a Saver, then yes.
timbecile
Posts: 110
Joined: Mon Mar 12, 2018 11:00 pm

Re: Save System Menu?

Post by timbecile »

ok, another question...

I'm trying to set up using SaveSystem.LoadScene, but it's not putting my player at the proper spawn point (made sure the names are correct). How does the save system determine what game object is the player?
User avatar
Tony Li
Posts: 21080
Joined: Thu Jul 18, 2013 1:27 pm

Re: Save System Menu?

Post by Tony Li »

Hi,

The player GameObject needs a Position Saver. Tick its Use Player Spawnpoint checkbox.
timbecile
Posts: 110
Joined: Mon Mar 12, 2018 11:00 pm

Re: Save System Menu?

Post by timbecile »

That was it! Just didn't have the checkbox ticked. Thanks again Tony!
Post Reply