This is the error, I’ve searched in the entire solution for every LazyValue reference to see if I was missing any .value parameter, but that’s not my case.
The problem is that I have no idea on how to debug this kind of error…
*note that the error can be reproduced also without a save file present.
Indeed I’ve deleted the old one but the error still remain
Maybe. You can set a Vector3 as a lazy value, that’s no problem. But if you try to return guardPosition in CaptureState without serializing it, that would cause your error.
Taking a look at the error again, it is talking about deserialize (check out line 53 of SavingSystem). So it does sound like you have updated the code and then tried to load an old (or non existent) save file. There is a fix at some point (can’t remember exactly when) for trying to load when no file is present.
Anyhow, I think LazyValue is a sideshow, not the real thing. Clear out your save, make sure you aren’t trying to load when the file is non-existent and see if that helps.
I’ve dig on it even more, and the issue is not about LazyValue or the Portal but in Save and SavingWarper but I notice that the portal script and also the SavingWarper get changed once the project is completed, so for now I will survive without saving and changing level.
If you are returning a LazyValue<Vector3>.value, you will encounter the same serialization issues as if you were returning the LazyValue itself. You have to convert the LazyValue<Vector3>.value into a SerializableVector3.
public object CaptureState()
{
return new SerializableVector3(guardPosition.value);
}
public void RestoreState(object state)
{
SerializableVector3 serializableVector3 = (SerializableVector3)state;
guardPosition.value = serializableVector3.ToVector();
}
And of course, you’ll need to delete the existing save file.
Fact is that I have only 1 CaptureState in the entire project at the moment and is just about the Mover.cs and it even rise the error.
public object CaptureState()
{
try
{
return new SerializableVector3(transform.position);
}
catch (System.Exception)
{
Debug.LogWarning("Something goes wrong with saving file, try later, or delete the save file.");
return null;
}
}
public void RestoreState(object state)
{
SerializableVector3 position = (SerializableVector3)state;
navMeshAgent.enabled = false;
transform.position = position.ToVector();
navMeshAgent.enabled = true;
}
Anyway I just completed the Fighter To Weapon Communication but even after the refactoring still getting the error, the best way to understand what’s going wrong, I guess is to spam on console the dictionary with the value to understand what’s going wrong… maybe?
In that case, I highly recommend you use the provided Saving package and remove your current files. We at least know the issues is not in there and its somewhere else
If this is causing an error, then there is something else going very very wrong.
Zip up your project and upload it to https://gdev.tv/projectupload and I’ll take a look.