How to build out without build keeping saves?

Discussion and help for Easy Save 3
poptarts4444
Posts: 18
Joined: Sat Jul 15, 2023 2:58 am

How to build out without build keeping saves?

Post by poptarts4444 »

So I'm mainly saving through ScriptableObjects. Everything works fine, but if I build my game, the game will load with all the saved data from when I'm in Editor. Even if I open on another computer. I would assume because it's building out what is currently inside the project.

What is the best way to build out with everything cleared every time? Maybe I'm just misunderstanding something too.
Notso
Posts: 51
Joined: Sat May 08, 2021 6:53 pm

Re: How to build out without build keeping saves?

Post by Notso »

Not sure I understand totally but if you are saving values into a scriptable object, then that would be why.
They retain data even after play.
That might be the issue here.
I am sure Joel might have more insight though.
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: How to build out without build keeping saves?

Post by Joel »

Hi there,

What platform are you building for? If you're building for standalone Windows player then the persistent data folder is the same location as the Windows editor (this is only the case for Windows and all other platforms use separate locations).

In this case you would need to manually delete the data, which you can do by clearing the persistent data path (Tools > Easy Save 3 > Clear Persistent Data Path). This will clear it for both Editor and Build.

If you want the Windows Editor and Windows Standalone Build to use two different locations then you would need to use platform-dependent compilation and use a sub-folder for one of the platforms. For example:

Code: Select all

#if UNITY_EDITOR
string filePath = "Editor/SaveFile.es3";
#else
string filePath = "SaveFile.es3";
#endif

ES3.Save("key1", 123, filePath);
ES3.Save("key2", 123, filePath);
ES3.Save("key3", 123, filePath);

// And do the same when loading.
Or if you're using Auto Save, do this in every scene before Auto Save gets called:

Code: Select all

#if UNITY_EDITOR
ES3AutoSaveMgr.Current.settings.path = "Editor/MyFile.es3";
#else
ES3AutoSaveMgr.Current.settings.path = "MyFile.es3";
#endif
All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
poptarts4444
Posts: 18
Joined: Sat Jul 15, 2023 2:58 am

Re: How to build out without build keeping saves?

Post by poptarts4444 »

Joel wrote: Sun Mar 17, 2024 8:57 am Hi there,

What platform are you building for? If you're building for standalone Windows player then the persistent data folder is the same location as the Windows editor (this is only the case for Windows and all other platforms use separate locations).

In this case you would need to manually delete the data, which you can do by clearing the persistent data path (Tools > Easy Save 3 > Clear Persistent Data Path). This will clear it for both Editor and Build.

If you want the Windows Editor and Windows Standalone Build to use two different locations then you would need to use platform-dependent compilation and use a sub-folder for one of the platforms. For example:

Code: Select all

#if UNITY_EDITOR
string filePath = "Editor/SaveFile.es3";
#else
string filePath = "SaveFile.es3";
#endif

ES3.Save("key1", 123, filePath);
ES3.Save("key2", 123, filePath);
ES3.Save("key3", 123, filePath);

// And do the same when loading.
Or if you're using Auto Save, do this in every scene before Auto Save gets called:

Code: Select all

#if UNITY_EDITOR
ES3AutoSaveMgr.Current.settings.path = "Editor/MyFile.es3";
#else
ES3AutoSaveMgr.Current.settings.path = "MyFile.es3";
#endif
All the best,
Joel
perfect this is exactly what I needed! will try this afternoon.
poptarts4444
Posts: 18
Joined: Sat Jul 15, 2023 2:58 am

Re: How to build out without build keeping saves?

Post by poptarts4444 »

Joel wrote: Sun Mar 17, 2024 8:57 am Hi there,

What platform are you building for? If you're building for standalone Windows player then the persistent data folder is the same location as the Windows editor (this is only the case for Windows and all other platforms use separate locations).

In this case you would need to manually delete the data, which you can do by clearing the persistent data path (Tools > Easy Save 3 > Clear Persistent Data Path). This will clear it for both Editor and Build.

If you want the Windows Editor and Windows Standalone Build to use two different locations then you would need to use platform-dependent compilation and use a sub-folder for one of the platforms. For example:
I got the different save locations workin!

I guess an additional question would be do people typically set something up where on build creation it would automatically clear the data? since Im gathering that right now I would need to just make sure I'm clearing all SOs everytime I build since otherwise the data in those SO will save out into the build.

Since obviously when I'm developing I need to be using the stuff that I've saved, but I don't want that same data to get built out.
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: How to build out without build keeping saves?

Post by Joel »

Hi there,

Glad you managed to get that working :)

To clear your save data on build you would use Unity's OnPreprocessBuild event:
https://docs.unity3d.com/ScriptReferenc ... Build.html

This might look something like this:

Code: Select all

using UnityEditor;
using UnityEditor.Build;
using UnityEditor.Build.Reporting;
using UnityEngine;

class MyCustomBuildProcessor : IPreprocessBuildWithReport
{
    public int callbackOrder { get { return 0; } }
    public void OnPreprocessBuild(BuildReport report)
    {
        ES3.DeleteFile("SaveFile.es3");
    }
}
As it's an Editor script, this would need to be placed in an Editor folder.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
poptarts4444
Posts: 18
Joined: Sat Jul 15, 2023 2:58 am

Re: How to build out without build keeping saves?

Post by poptarts4444 »

Joel wrote: Mon Mar 18, 2024 8:26 am Hi there,

Glad you managed to get that working :)

To clear your save data on build you would use Unity's OnPreprocessBuild event:
https://docs.unity3d.com/ScriptReferenc ... Build.html

This might look something like this:

Code: Select all

using UnityEditor;
using UnityEditor.Build;
using UnityEditor.Build.Reporting;
using UnityEngine;

class MyCustomBuildProcessor : IPreprocessBuildWithReport
{
    public int callbackOrder { get { return 0; } }
    public void OnPreprocessBuild(BuildReport report)
    {
        ES3.DeleteFile("SaveFile.es3");
    }
}
As it's an Editor script, this would need to be placed in an Editor folder.

All the best,
Joel
rather than delete the file, I'd probably just clear the SO data. Since I'd want the data to test the build on my machine. Is there a built-in way through ES3 to reset values that are typically loaded/saved though? I would assume not lol but figured I would ask.
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: How to build out without build keeping saves?

Post by Joel »

I'm not sure what you mean by "clear the SO data", could you clarify?

If you mean just clear the data you've saved regarding ScriptableObjects you can use ES3.DeleteKey to delete individual keys if you've saved your SO data to a separate key.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
poptarts4444
Posts: 18
Joined: Sat Jul 15, 2023 2:58 am

Re: How to build out without build keeping saves?

Post by poptarts4444 »

Joel wrote: Tue Mar 19, 2024 8:24 am I'm not sure what you mean by "clear the SO data", could you clarify?

If you mean just clear the data you've saved regarding ScriptableObjects you can use ES3.DeleteKey to delete individual keys if you've saved your SO data to a separate key.

All the best,
Joel
yeah sorry it's kind of hard to describe. So let's say I have an SO called DataSO that holds a float value. When loading a save I will fill in that float with the loaded float. If I'm playtesting my game in the editor, then values will be in those SOs in the editor. So that DataSO will have some float assigned.

If I build at that point, then that DataSO will still have that data in it. If the build already has a save, then it's no issue since it will just overwrite the float. If this is the first time the build is running though, then the SO won't get overwritten and the game will start with that float filled in. Does that make sense?

Basically, now I set up a script that resets all SOs that I've saving/loading before making a new build, but I go and manually run it. That way they are "blank" for a new build save. I guess I'm a little surprised that people don't run into this often since I'm not sure how else to go about it if I'm using SOs.
Notso
Posts: 51
Joined: Sat May 08, 2021 6:53 pm

Re: How to build out without build keeping saves?

Post by Notso »

I do something similar for a few values, what you could do is have the SO value then a runtime value, and set the runtime value = default.
Then you can just save the runtime value and reload the runtime value.
But for a build the default value will always be the original float you want.
Keep in mind you would have to change the scripts to use the runtime value though, but this method is a bit easier to do.
That script to reset all SO, you could also run that on game start to make sure everything is reset as well.
Example of my shared float:

Code: Select all

[CreateAssetMenu( menuName ="Scriptable Objects/Shared Variables/Shared Float")]
public class SharedFloat : ScriptableObject, ISerializationCallbackReceiver, IGameResetReceiver
{
    [SerializeField]
    private float _value = 0.0f;
    [SerializeField]
    private float _runtimeValue = 0.0f;

    public float value
    {
        get { return this._runtimeValue; }
        set { this._runtimeValue = value;}
    }
    public void OnAfterDeserialize() { _runtimeValue = _value; }
    public void OnBeforeSerialize() { }
    public void OnGameReset()
    {
        OnAfterDeserialize();
    }
}
Now I just create a list of scriptables

Code: Select all

[SerializeField] private List<SharedFloat> scriptables;
Then in my save method
(I only delete to make sure I get the current values and nothing gets left behind that shouldn't be)

Code: Select all

ES3.DeleteKey("Scriptables");

Code: Select all

ES3.Save("Scriptables", scriptables);
And to load them back

Code: Select all

if (ES3.KeyExists("Scriptables")) ES3.LoadInto("Scriptables", scriptables);
Post Reply