No Save!

Hi,
for some reason my project is not saving data // and or getting data, at start().

I’ve tried Binary and PlayerPrefs (both have been reliable for me historically). I’m wondering if anyone dealt with this? Maybe some setting in the Project Settings?

Thanks!

you mention playerprefs and binary, which leads me to believe you’re not referring to the unity serialization of assets, but rather an actual save game implementation you’ve done.

Since there are a bajillions ways to implement a save system, you’re going to have to share your code so we know what you did.

4 Likes

There is no inherent way to load / save state in Unity. It’s all on what you wrote or what you bought from the asset store, so it sounds like perhaps you just have a bug / bugs.

Here’s the skinny on load / save:

Load/Save steps:

An excellent discussion of loading/saving in Unity3D by Xarbrough:

And another excellent set of notes and considerations by karliss_coldwild:

Loading/Saving ScriptableObjects by a proxy identifier such as name:

When loading, you can never re-create a MonoBehaviour or ScriptableObject instance directly from JSON. Save data needs to be all entirely plain C# data with no Unity objects in it.

The reason is they are hybrid C# and native engine objects, and when the JSON package calls new to make one, it cannot make the native engine portion of the object, so you end up with a defective “dead” Unity object.

Instead you must first create the MonoBehaviour using AddComponent() on a GameObject instance, or use ScriptableObject.CreateInstance() to make your SO, then use the appropriate JSON “populate object” call to fill in its public fields.

If you want to use PlayerPrefs to save your game, it’s always better to use a JSON-based wrapper such as this one I forked from a fellow named Brett M Johnson on github:

Do not use the binary formatter/serializer: it is insecure, it cannot be made secure, and it makes debugging very difficult, plus it actually will NOT prevent people from modifying your save data on their computers.

2 Likes

Additionally it’s been completely removed in recent releases of .NET which Unity will eventually be using once they finally finish the upgrade to the scripting runtime. If you want binary serialization Unity provides a package with support for it.

Ideally you shouldn’t use PlayerPrefs either because for some reason they thought it was a good idea to have it store data in the system registry on Windows. On every other platform it’s fine, and in the case of WebGL likely the only approach to saving data locally (albeit it will disappear if the user clears their privacy data).

https://docs.unity3d.com/Packages/com.unity.serialization@3.1/manual/index.html

1 Like

@All
UPDATE: So it appears the one step I needed to take was to (at Start), force/make the Progress Binary null, and then retrieve it. My bet is it was holding onto an object which was not updated.

THANKS