Save System and Manager classes

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
darkdollgames
Posts: 8
Joined: Fri Sep 20, 2024 9:57 pm

Save System and Manager classes

Post by darkdollgames »

Hello! If this has been asked/solved before, I couldn't find it for the life of me.

I'm using the DS save system and it's coming together, but for some reason I can't figure out how to get my Manager classes to load when I load a game.

What saver component should I be attaching to things like my PlayerManager, UIManager, AudioManager, etc? I made a "don'tdestoryonload" component so they'll persist, and I attache a SpawnedObject component, but that didn't do it.

For reference, if I start the game in a scene with all of the manager prefabs in the scene, then load the game, it works fine. However if I save the game in a scene without them, then load, the prefabs aren't there.

Any help is appreciated! If I need to provide the project file I can.
User avatar
Tony Li
Posts: 23250
Joined: Thu Jul 18, 2013 1:27 pm

Re: Save System and Manager classes

Post by Tony Li »

Hi,

The save system's spawned object system is usually used to respawn objects like monsters and treasure that pop into the game at runtime and don't persist across scenes (i.e., not Don't Destroy On Load).

For persistent GameObjects, it's probably better to handle it with a separate script, not the spawned object system. You could write a script that has references to the manager prefabs. Put this script on a non-DontDestroyOnLoad GameObject in the scene. In Awake(), if instances don't exist, instantiate them. Something like:

Code: Select all

using UnityEngine;
public class InstantiateManagers : MonoBehaviour
{
    public PlayerManager playerManagerPrefab;
    public AudioManager audioManagerPrefab;
    
    void Awake()
    {
        if (FindFirstObjectByType<PlayerManager>() == null) Instantiate(playerManagerPrefab);
        if (FindFirstObjectByType<AudioManager>() == null) Instantiate(audioManagerPrefab);
    }
}
darkdollgames
Posts: 8
Joined: Fri Sep 20, 2024 9:57 pm

Re: Save System and Manager classes

Post by darkdollgames »

Ok that's kind of what I figured. This will work just fine, thank you for the quick reply. The DS asset is already great, but the support for it makes it easily one of the best assets there is.
User avatar
Tony Li
Posts: 23250
Joined: Thu Jul 18, 2013 1:27 pm

Re: Save System and Manager classes

Post by Tony Li »

Thanks! Glad to help!
Post Reply