0

So, I have a scriptable object, which I need to keep track of a date. Because scriptable objects don't keep track of the date between runtime on their own, I came up with the following:

public long EndTimeLong;
private DateTime endTime;
public DateTime EndTime
{
    get
    {
        return endTime;
    }
    set
    {
        EndTimeLong = value.ToBinary();
        endTime = value;
    }
}

So, setting the EndTime to any value, stores it as Binary in EndTimeLong.

Then right before I ever use this at runtime, I call the following method:

public void ReInit()
{
    EndTime = DateTime.FromBinary(EndTimeLong);
    ...
}

So, before I use the scriptable object at all, the original date should be restored.

However, this seems to work find in editor, but it doesn't when in Android.

The way I can tell is that in editor, I run a method which sets endtime to be 60 seconds in the future. I then stop and start the editor playing, and it knows that endtime is in the future still and acts accordingly. (shows some things etc) On android however, it treats it as though the time is not in the future. Why would this behavior be different between the two? And how could I resolve this?

Cabrra
  • 644
  • 3
  • 14
  • 28
pingu2k4
  • 956
  • 2
  • 15
  • 31

1 Answers1

0

I'm assuming you are writing your EndTimeLong value to a file between sessions and that is how you are loading it later. If you provide more information about how you are saving your data between sessions we may be able to provide more help.

That being said, if this is all that you need to save between sessions I would instead make use of Unity's PlayerPref stuff: https://docs.unity3d.com/ScriptReference/PlayerPrefs.html