Save System Question ;)
Re: Save System Question ;)
This looks really nice... but seems to only work on stuff that is already in the scene... hellodear.in
teatv download
teatv download
Last edited by taareni9 on Fri May 20, 2022 3:50 am, edited 1 time in total.
Re: Save System Question ;)
Hi,
You can also set up savers to save data that's not in the scene, such as in ScriptableObject assets and non-GameObject classes. And by keeping the 'Save Across Scene Changes' checkbox ticked on a saver, the save system will retain that saver's data across scene changes (i.e., when the object isn't in the scene) so it can restore the state when it returns to the object's scene.
Re: Save System Question ;)
To expand on what Tony wrote, all you need to have is a SpawnedObjectManager on a gameobject in the scene (that has a list of the prefabs that are going to get instantiated/spawned that you want to keep saved), and those same prefabs (to be able to get added to the SpawnedObjectManager), will need to have "SpawnedObject" script on them
Then whenever you change scene, you need to use the SaveSystem. sceneloading features (link to all 4 ways to changes scene was posted by Tony on page 5)
Re: Save System Question ;)
Hey Tony!
Decided to dig a bit a few pages ago and find my old topic on save system back since its "somewhat" of a followup question
AS you know, we are using your saving system for our game...
However, I have noticed a few "issues" that I am not certain how to solve...
Particularly the "Position Saver" which I have taken "as is"...
Gonna try to explain properly so you understand
Right now our "Main Character Controler" is a pretty big prefab which has all the stuff that should remain across scenes (dont destroy on load)
To make sure I only ever had one of those, I spawn it using a "persistant object spawner" with a static bool :
simple enough... the issue is that the restore data on the save prefab will not work if set to anything lower than 3 frames to wait before restore.. and even then, some times if the loading "lags" a bit more, position isnt restored and the gameobject restarts from its starting position...
I tried to remove the above code and simply put the prefab directly in the scene, but that end up causing issue when changing scenes because it spawns a new version of it and there is a tiny few frames delay before it gets deleted/removed
So basically if i use the spawner, i need to delay restore otherwise it doesnt work (but this looks weird since the jump is noticeable)
OR i run into various issues/crash with a duplicate prefab
What would be your suggestion to solve this?
AS always, thank you very much for your time and have a nice day!
Decided to dig a bit a few pages ago and find my old topic on save system back since its "somewhat" of a followup question
AS you know, we are using your saving system for our game...
However, I have noticed a few "issues" that I am not certain how to solve...
Particularly the "Position Saver" which I have taken "as is"...
Gonna try to explain properly so you understand
Right now our "Main Character Controler" is a pretty big prefab which has all the stuff that should remain across scenes (dont destroy on load)
To make sure I only ever had one of those, I spawn it using a "persistant object spawner" with a static bool :
Code: Select all
public class PeristentObjectSpawner : MonoBehaviour
{
// CONFIG DATA
[Tooltip("This prefab will only be spawned once and persisted between " +
"scenes.")]
[SerializeField] GameObject persistentObjectPrefab = null;
// PRIVATE STATE
static bool hasSpawned = false;
// PRIVATE
private void Awake() {
if (hasSpawned) return;
SpawnPersistentObjects();
hasSpawned = true;
}
private void SpawnPersistentObjects()
{
GameObject persistentObject = Instantiate(persistentObjectPrefab, this.gameObject.transform.position, this.gameObject.transform.rotation);
DontDestroyOnLoad(persistentObject);
}
}
I tried to remove the above code and simply put the prefab directly in the scene, but that end up causing issue when changing scenes because it spawns a new version of it and there is a tiny few frames delay before it gets deleted/removed
So basically if i use the spawner, i need to delay restore otherwise it doesnt work (but this looks weird since the jump is noticeable)
OR i run into various issues/crash with a duplicate prefab
What would be your suggestion to solve this?
AS always, thank you very much for your time and have a nice day!
Re: Save System Question ;)
I think the first step is to get to the bottom of why it's not restoring right away. It should work if you set the Save System component's Frames To Wait Before Apply Data to 1. This will give your instantiated prefab a frame to initialize and register with the save system.
What are the values on your player's Position Saver?
Do any scripts in your player prefab's hierarchy initialize themselves (in particular their positions) in Start()? If so, you may need to set Frames To Wait Before Apply Data to 2.
I also recommend setting up a Standard Scene Transition Manager to fade to/from black when changing scenes and loading games.
What are the values on your player's Position Saver?
Do any scripts in your player prefab's hierarchy initialize themselves (in particular their positions) in Start()? If so, you may need to set Frames To Wait Before Apply Data to 2.
I also recommend setting up a Standard Scene Transition Manager to fade to/from black when changing scenes and loading games.
Re: Save System Question ;)
I just checked the save file (which i do not encrypt for now so its easier to debug/test)
this is the only one that edits any kind of "position" on the main prefab
(also wondering why there is positions and position but thats not important)
"key": "CharPositionSaver",
"sceneIndex": -1,
"data": "{\n \"positions\": [\n {\n \"scene\": 0,\n \"position\": {\n \"x\": 21.2435302734375,\n \"y\": -6.889900207519531,\n \"z\": 66.82514190673828\n },\n \"rotation\": {\n \"x\": 0.0,\n \"y\": 0.8612263202667236,\n \"z\": 0.0,\n \"w\": 0.5082217454910278\n }\n }\n ]\n}"
setting the frame to wait to 1 DOES work most of the times... its just that once in a while there is some lag when pressing play in the editor and it doesnt...
I 100% agree about the "Standard Scene Transition Manager"... I have been thinking about it for a while...
I know you got something like that in your amazing system...
do you have any documentation link on how to properly set-it-up?
while i did make one in my scenemanager when transitioning scenes, it doesnt do any fade "on start" when i load for the first time... and its assuredly much less "well made" than whatever you did
Thank you always!
this is the only one that edits any kind of "position" on the main prefab
(also wondering why there is positions and position but thats not important)
"key": "CharPositionSaver",
"sceneIndex": -1,
"data": "{\n \"positions\": [\n {\n \"scene\": 0,\n \"position\": {\n \"x\": 21.2435302734375,\n \"y\": -6.889900207519531,\n \"z\": 66.82514190673828\n },\n \"rotation\": {\n \"x\": 0.0,\n \"y\": 0.8612263202667236,\n \"z\": 0.0,\n \"w\": 0.5082217454910278\n }\n }\n ]\n}"
setting the frame to wait to 1 DOES work most of the times... its just that once in a while there is some lag when pressing play in the editor and it doesnt...
I 100% agree about the "Standard Scene Transition Manager"... I have been thinking about it for a while...
I know you got something like that in your amazing system...
do you have any documentation link on how to properly set-it-up?
while i did make one in my scenemanager when transitioning scenes, it doesnt do any fade "on start" when i load for the first time... and its assuredly much less "well made" than whatever you did
Thank you always!
Re: Save System Question ;)
Hi,
Does the saved position look correct in the save data? If so, you could temporarily add a Debug.Log to the PositionSaver method that sets the player's position. Then add similar Debug.Logs to any of your own initialization code that moves the player. Maybe the order isn't what you intend.HawkX wrote: ↑Thu Jun 09, 2022 1:21 pmI just checked the save file (which i do not encrypt for now so its easier to debug/test)
this is the only one that edits any kind of "position" on the main prefab
...
"key": "CharPositionSaver",
"sceneIndex": -1,
"data": "{\n \"positions\": [\n {\n \"scene\": 0,\n \"position\": {\n \"x\": 21.2435302734375,\n \"y\": -6.889900207519531,\n \"z\": 66.82514190673828\n },\n \"rotation\": {\n \"x\": 0.0,\n \"y\": 0.8612263202667236,\n \"z\": 0.0,\n \"w\": 0.5082217454910278\n }\n }\n ]\n}"
If you tick the Multiscene checkbox, it will save the player's last position in every scene that the player leaves. In most games, this isn't relevant because you're either saving your game in a single position, or you're changing scenes using spawnpoints.
That suggests that maybe you have a coroutine or something similar that updates the player position after the PositionSaver moves the player.
It only fades when changing scenes or loading a saved game. But you can use a FadeIn() sequencer command to fade in on play like DemoScene1 if you want to do that. The easiest ways to set up the Standard Scene Transition Manager are to copy the setup on DemoScene1's Dialogue Manager, or download the SaveSystem prefabs from the Dialogue System Extras page.HawkX wrote: ↑Thu Jun 09, 2022 1:21 pmI 100% agree about the "Standard Scene Transition Manager"... I have been thinking about it for a while...
I know you got something like that in your amazing system...
do you have any documentation link on how to properly set-it-up?
while i did make one in my scenemanager when transitioning scenes, it doesnt do any fade "on start" when i load for the first time... and its assuredly much less "well made" than whatever you did
Re: Save System Question ;)
wow.. thank you so much for all of that
For the position(s) I will uncheck the multi-scene i didnt properly understand what it meant... thanks for the explanation
For the position not "always" getting restored, its really weird because beside the 3rd person character controller script, there is absolutely nothing that updates that game object position... i'll leave it at 1 frame for now and add a couple of debug like you suggested to see why and what happens (whenever it does again, it didnt today when testing)
Finally I will 100% check those out and figure out the best way to implement that fade in/out for our game!
For the position(s) I will uncheck the multi-scene i didnt properly understand what it meant... thanks for the explanation
For the position not "always" getting restored, its really weird because beside the 3rd person character controller script, there is absolutely nothing that updates that game object position... i'll leave it at 1 frame for now and add a couple of debug like you suggested to see why and what happens (whenever it does again, it didnt today when testing)
Finally I will 100% check those out and figure out the best way to implement that fade in/out for our game!
Re: Save System Question ;)
Update + Another new "question" LOL...
I have made major progress with your suggestions!
It has been working fine so far with 1 frame delay... (i have yet to add a default fade in on first load to my loader - or convert everything to use your own) but at least its working!
My question of the day is about the "auto save load"
Would it be "possible" to edit that easily to change it to accept a scene "string/name" instead of its build id?
because quite often scenes get moved around in the build order, and i dont want the game to auto-save when quitting during a combat in a turn based combat scene
As always, Thanks for everything!!
I have made major progress with your suggestions!
It has been working fine so far with 1 frame delay... (i have yet to add a default fade in on first load to my loader - or convert everything to use your own) but at least its working!
My question of the day is about the "auto save load"
Would it be "possible" to edit that easily to change it to accept a scene "string/name" instead of its build id?
because quite often scenes get moved around in the build order, and i dont want the game to auto-save when quitting during a combat in a turn based combat scene
As always, Thanks for everything!!
Re: Save System Question ;)
If the Save System's "Save Current Scene" checkbox is ticked, it will save the current scene by name.
The Auto Save Load's "Don't Save In Scenes" list uses scene IDs because you most often exclude a splash scene and start scene from saving, and those are almost always scene indices 0 and 1. This makes it easy to swap out the splash and/or start scene without having to worry about matching names. But feel free to duplicate the script and change it to use scene names here, too, if you prefer.
The Auto Save Load's "Don't Save In Scenes" list uses scene IDs because you most often exclude a splash scene and start scene from saving, and those are almost always scene indices 0 and 1. This makes it easy to swap out the splash and/or start scene without having to worry about matching names. But feel free to duplicate the script and change it to use scene names here, too, if you prefer.