# Save/Load Manager

<div align="left"><figure><img src="https://3303637552-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOAGs3il6rJbkejwPOlEP%2Fuploads%2FOXndO6hKeLj0uEuE8Vaf%2FActorComponent_64x.png?alt=media&#x26;token=b00844b2-cbc3-4f89-9f4b-d2c8e193007c" alt=""><figcaption></figcaption></figure></div>

The **Save/Load Manager(AC\_SaveLoadManager)** is a highly versatile component designed to manage all saving and loading operations. It tracks saved data, interacts with the selected save slot stored in the **Game Instance**, and uses **FInstancedStructs** to handle diverse data types. This ensures modularity and flexibility, allowing any type of game data to be saved or loaded seamlessly.

It is added to the **PlayerController** class by default **(PC\_SoulslikeFramework).**

### Functionality

* Works with the **Game Instance** to determine which save slot to handle.
* Utilizes **FInstancedStruct** to save and load any type of data (e.g., stats, inventory, equipment, world state).
  * Converts data into serialized structures for storage and retrieval.
* **Dynamic Save/Load Functionality**:
  * Saves game data dynamically based on the active save slot.
* **Event-Driven Updates**:
  * Dispatches events to notify other components or systems when data is loaded.

### **How It Works**

Main method - **Event UpdateSaveData:** Utilized to add/update our save data. Any type of data can be stored/retrieved in the save file thanks to **Instanced Structures:**

<figure><img src="https://3303637552-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOAGs3il6rJbkejwPOlEP%2Fuploads%2FvL8ujxjngud0vBZKlV2C%2Fimage.png?alt=media&#x26;token=2d852460-80a0-456c-b25b-46d076a6023b" alt=""><figcaption></figcaption></figure>

Additionally, helper method - **Event AddToSaveData:** Used to add new data to an existing data entry:

<figure><img src="https://3303637552-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOAGs3il6rJbkejwPOlEP%2Fuploads%2FurhLwnZy6APPHzTXkIPV%2Fimage.png?alt=media&#x26;token=37f913f5-b513-4d1f-b528-993924335fb0" alt=""><figcaption></figcaption></figure>

These events are triggered from various blueprints. If you'd like to see where, see our page related to [Finding References](https://soulslike-framework.isik.vip/getting-started/finding-references).

### Saving Components

Each component has a method of "serializing" their data into a savable structure format:

<figure><img src="https://3303637552-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOAGs3il6rJbkejwPOlEP%2Fuploads%2FVPtrd6QvrezxDbPbr6dF%2Fimage.png?alt=media&#x26;token=c7395250-196e-4779-a507-1ea68dfba511" alt=""><figcaption><p>Example from AC_EquipmentManager</p></figcaption></figure>

This method adds the related save data to the main data we have in our save/load component. Each component that has data that needs to be saved implements a similar method.&#x20;

Additionally, **AC\_SaveLoadManager** has methods for serializing all of the components.

When the save data inside **AC\_SaveLoadManager** is updated, data will be saved into file.

### Loading Components

The save/load manager sends a message which **each component that requires loading** listens to:

<figure><img src="https://3303637552-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOAGs3il6rJbkejwPOlEP%2Fuploads%2FLiASzUy0BMBNeE0nq45z%2Fimage.png?alt=media&#x26;token=34b1ee6f-dd45-4db2-b0e7-5c727887ae1d" alt=""><figcaption></figcaption></figure>

When this dispatcher is called, each component that is listening to it will execute a relevant method:

<figure><img src="https://3303637552-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOAGs3il6rJbkejwPOlEP%2Fuploads%2FV4M3vk14ukXvi8Q9cRlZ%2Fimage.png?alt=media&#x26;token=ad0d4d5f-2fd4-4012-9223-ffdc8add8930" alt=""><figcaption><p>Example from AC_InventoryManager</p></figcaption></figure>

### Saving World Actors (Interactables & NPC's)

Actors that need to be saved require a unique identifier. For this, we utilize **GUID's** in Soulslike Framework. Actors without a valid GUID won't be considered for saving:

<figure><img src="https://3303637552-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOAGs3il6rJbkejwPOlEP%2Fuploads%2FAQZvgnnVpDA37p2HDC0Q%2Fimage.png?alt=media&#x26;token=04ea40e0-666d-441e-9736-80962fde6ead" alt=""><figcaption></figcaption></figure>

For example, when this container actor (B\_Container) is interacted with, it calls a method to update our save data:

<figure><img src="https://3303637552-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOAGs3il6rJbkejwPOlEP%2Fuploads%2F9V71ZlhIuBPeI5Zp3dG0%2Fimage.png?alt=media&#x26;token=77429a99-a53c-4976-a302-19ac5c009c7e" alt=""><figcaption><p>Method screenshot from B_Interactable</p></figcaption></figure>

After our save data has changed/updated, it gets serialized and saved automatically into a file.

### Loading World Actors (Pickup Items, Interactables, NPC's)

Similarly, actors that require loading bind to AC\_SaveLoadManager's **OnDataLoaded()** delegate. This way, when data is loaded, we can execute any desired logic.

<figure><img src="https://3303637552-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOAGs3il6rJbkejwPOlEP%2Fuploads%2FFEpB3oxTJflgQAkcs0Jw%2Fimage.png?alt=media&#x26;token=c5794fcd-3013-4618-83cb-96bccab76446" alt=""><figcaption><p>Load event from B_Interactable</p></figcaption></figure>
