# Save/Load System

## Overview

The Save/Load system of the Inventory System is based off of JSON.Net.

{% embed url="https://www.newtonsoft.com/json" %}

Unity officially supports it, but does not support native Unity types like Gameobject or Vector3 etc, by default. You can use converters to get around it, but for now, that's not necessary.



## Setting up the System

To set up the Save/Load system is super easy.

You can either make your own buttons/conditions for it, but in the InventoryCanvas, under the InventoryTabsArea, I've added a Save/Load button there for you.

To Save/Load, you simply either need to set the buttons up like this:

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2FzWAFs06szPD9aYjRHDdd%2Fimage.png?alt=media&#x26;token=b8316820-5434-4082-93bd-376fbe9c87ff" alt=""><figcaption><p>Saving</p></figcaption></figure>

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2FqieaHk9gw79Bk1N9gi14%2Fimage.png?alt=media&#x26;token=bece378c-6311-431f-93c6-9b04c1d44d0f" alt=""><figcaption><p>Loading</p></figcaption></figure>

OR if you want to have another method to call Saving/Loading, just simply find a reference to InventoryMaster, and call:

* To Save -> SerializeJSON()
* To Load -> DeserializeJSON()

And that's it.\
\
It will then save at: Application.persistentDataPath under the file name of: playerInventories.json



## Encryption

If you wish to enable AES256 encryption on your save data, you can simply do so by turning on **Using Save System Encryption?** on the Inventory Master component.

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2Fhj9JvPlneyx74kQhWpty%2Fimage.png?alt=media&#x26;token=3288095d-45e5-4188-b2b4-40e66c3d7857" alt=""><figcaption></figcaption></figure>

This will then encrypt your data to AES256 standard. You can find the Key and IV it uses to encrypt inside the JSONDataService.cs script:\
\


<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2Fuy1mwqHDBQHQsP0Wkx4C%2Fimage.png?alt=media&#x26;token=d5b1b9f8-ea6b-4369-8d4f-7907e21f3398" alt=""><figcaption></figcaption></figure>

If you want to generate a new KEY and IV, the easiest way I've found is to just use ChatGPT.

Simply ask it as I have below:\


<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2FhQkrMsK4OpXTWZNkSlEs%2Fimage.png?alt=media&#x26;token=9e1c29e5-f7e4-4ffa-a2ed-516b7bd87bb8" alt=""><figcaption></figcaption></figure>
