End of Stream encountered before parsing was completed

Hello everyone!
I’am trying to debug this error, but I can’t fix it,
does anyone know what caused it?

SerializationException: End of Stream encountered before parsing was completed.
System.Runtime.Serialization.Formatters.Binary.__BinaryParser.Run () (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize (System.Runtime.Remoting.Messaging.HeaderHandler handler, System.Runtime.Serialization.Formatters.Binary.__BinaryParser serParser, System.Boolean fCheck, System.Boolean isCrossAppDomain, System.Runtime.Remoting.Messaging.IMethodCallMessage methodCallMessage) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize (System.IO.Stream serializationStream, System.Runtime.Remoting.Messaging.HeaderHandler handler, System.Boolean fCheck, System.Boolean isCrossAppDomain, System.Runtime.Remoting.Messaging.IMethodCallMessage methodCallMessage) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize (System.IO.Stream serializationStream, System.Runtime.Remoting.Messaging.HeaderHandler handler, System.Boolean fCheck, System.Runtime.Remoting.Messaging.IMethodCallMessage methodCallMessage) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize (System.IO.Stream serializationStream, System.Runtime.Remoting.Messaging.HeaderHandler handler, System.Boolean fCheck) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize (System.IO.Stream serializationStream, System.Runtime.Remoting.Messaging.HeaderHandler handler) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize (System.IO.Stream serializationStream) (at <695d1cc93cca45069c528c15c9fdd749>:0)
RPG.Saving.SavingSystem.LoadFile (System.String saveFile) (at Assets/Scripts/Saving/SavingSystem.cs:53)
RPG.Saving.SavingSystem+d__0.MoveNext () (at Assets/Scripts/Saving/SavingSystem.cs:16)
UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at :0)
UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
RPG.ScenaManagement.SavingWrapper:Awake() (at Assets/Scripts/SceneManagment/SavingWrapper.cs:16)
UnityEngine.Object:Instantiate(GameObject)
RPG.Core.PersistentObjectSpawner:SpawnPersistentObject() (at Assets/Scripts/Core/PersistentObjectSpawner.cs:23)
RPG.Core.PersistentObjectSpawner:Awake() (at Assets/Scripts/Core/PersistentObjectSpawner.cs:17)

This error is caused when an error previously occurred while saving.

The most common cause of this is returning a LazyValue in CaptureState instead of that LazyValue’s value.

For example, in Health.cs, assuming currentHealth is a LazyValue<Float>

public object CaptureState()
{
    return currentHealth;  //this will cause an error when saving
}

instead of

public object CaptureState()
{
    return currentHealth.value;  //this returns the underlying float value.
}

Go through your scripts and find any LazyValues that are being saved by the saving system, and make sure you’re saving the value, and not the LazyValue object itself.
The bad news is that once the save file has been corrupted in this manner, it must be deleted.

2 Likes

I’ve never heard the term ‘LazyValue’ so I looked it up and found this:

This particular article seems to be JS specific, but I write JS so I’m cool with it.

The fundamentals probably apply across the board. I’ve seen responses for Java and other languages, too.

I’ have just finished to do a LazyValue review into my project and the scripts were written correctly.

I would like to try to delete the save file , but i don’t find it. I’ don’t have any file Save.sav.
Thank you for your help!

Your save file path is specific to your operating system and your machine…
If you’re on windows, the Save file is most likely in

c:\Users\<yourUserName>\AppData\Roaming\LocalLow\DefaultCompany\<yourProgramName\Save.sav

In the RPG course, we use a custom class LazyValue.cs as a quick and easy Lazy Value setup. There is also a Lazy in the System Libraries, but it is meant more for multi-threaded applications (Unity is not multithreaded)

The purpose of Lazy Value is to avoid race conditions.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms