2D Platformer Microgame - Using the Manager approach.

Examples using Easy Save's API code
Post Reply
User avatar
Joel
Moodkie Staff
Posts: 5036
Joined: Wed Nov 07, 2012 10:32 pm

2D Platformer Microgame - Using the Manager approach.

Post by Joel »

The Manager Approach

This sample uses Unity's 2D Platformer Microgame learning template to demonstrate how you can incorporate Easy Save into a project using the Manager approach to saving and loading. This is where one Component handles all of the saving and loading for your scene, rather than getting objects to save themselves.

Pros
  • Can be more computationally efficient as it usually requires saving fewer keys to a file.
  • Doesn't require everything to have a unique ID (as arrays of objects are used instead), which can make things simpler.
  • Can be easier to debug as all of your save and load logic is in one place rather than spread across the scene.
Cons
  • The code can look more complex to beginners.
  • Because it's reliant on arrays, issues can occur if objects are reordered or removed.
Setup

In order to set up this example you will need to do the following:
  1. Ensure that you're using Unity 2020 or 2021, as Unity 2022 doesn't support Learning templates.
  2. Create a new '2D Platformer Microgame' project (Unity Hub > New Project > Editor Version: 2020 or 2021 > Learning > 2D Platformer Microgame > Create Project).
  3. Import Easy Save from the Package Manager (Window > Package Manager > My Assets > Easy Save > Import). You should also ensure that it's updated to the latest version of Easy Save.
  4. Download the UnityPackage attached below and import the package attached below by double-clicking it, or by going to Assets > Import Package > Custom Package.
  5. Open the Scene Assets > Easy Save > Examples > 2D Platformer Microgame - Manager Approach > EasySaveSampleScene.
  6. Go to File > Build Settings and press Add Open Scenes.
You may also receive the following error when running the project:
ArgumentException: An item with the same key has already been added.
This is due to a bug in Unity's Tutorial Framework. Although this error is harmless, you may want to go to Package Manager > Unity Registry > Tutorial Framework and select Remove to prevent it from appearing.

What changes were made

The following changes were made to the default scene:
  1. An Easy Save Manager was added to the scene by going to Tools > Easy Save 3 > Add Manager to Scene. This enables us to save and load things by reference.
  2. A GameObject named Save Manager was created and a SaveManager script added.
  3. Save and Load buttons were added to UI Canvas/Buttons, and these were hooked up to the Save() and Load() methods of the SaveManager script.
  4. The Load button was made non-interactable by default.
How it works

We recommend taking a look at SaveManager.cs in Assets > Easy Save 3 > Examples > 2D Platformer Microgame - Manager Approach. This is fully commented and explains exactly how each aspect works.

As an overview, the following happens in this scene:
  1. When the scene loads, it initialises the SaveManager's variables and then checks for save data.
  2. If there is save data, it will load the variables from the data and enable the Load button.
  3. When the user presses the Save button (located by pressing Esc), it will save the required variables to the default file and enable the Load button.
  4. When the user presses Load, it reloads the current scene. This in turn takes us back to Step 1.
Unity Package Download
2D Platformer Microgame - Manager Approach.unitypackage
(144.04 KiB) Downloaded 1252 times
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Post Reply