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.
Save System and Manager classes
Re: Save System and Manager classes
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:
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);
}
}
-
- Posts: 8
- Joined: Fri Sep 20, 2024 9:57 pm
Re: Save System and Manager classes
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.
Re: Save System and Manager classes
Thanks! Glad to help!