splinedrew
Member
Hello there! I am running into an issue of loading in custom meta data. I see the BasicSaveMetaDataCreator and tried to extend it to a custom class that saves a few custom variables. Would it be possible to see an example of how to integrate saving a float value to a game manager component?
For an example, I added the m_TimePlayed variable here. I then also have to add a line into the SaveViewModule to get the saved value.
My problem is that it is always displaying the GameManager value, and not the value that is saved into the meta data file. I'd love to see an example of the proper way to save/recall a simple value!
Thanks!
C#:
/// <summary>
/// The save meta data which can be serialized.
/// </summary>
[Serializable]
public class BasicSaveMetaData : SaveMetaData
{
[Tooltip("The date and time in ticks.")]
[SerializeField] protected long m_DateTimeTicks;
public long DateTimeTicks => m_DateTimeTicks;
private float m_TimePlayed;
public float TimePlayed => m_TimePlayed;
/// <summary>
/// Default constructor.
/// </summary>
public BasicSaveMetaData() : base()
{
m_DateTimeTicks = new DateTime().Ticks;
m_TimePlayed = GameManager.Instance.TimePlayed;
}
/// <summary>
/// Overloaded constructor.
/// </summary>
/// <param name="saveSystemManager">The save system manager.</param>
/// <param name="saveDataInfo">The save data info linked to that meta data.</param>
public BasicSaveMetaData(SaveSystemManager saveSystemManager, SaveDataInfo saveDataInfo) : base(saveSystemManager, saveDataInfo)
{
m_DateTimeTicks = DateTime.Now.Ticks;
m_TimePlayed = GameManager.Instance.TimePlayed;
}
/// <summary>
/// Set the date of the save data.
/// </summary>
/// <param name="newDateTime">The new date.</param>
public void SetDateTime(DateTime newDateTime)
{
m_DateTimeTicks = newDateTime.Ticks;
}
}
For an example, I added the m_TimePlayed variable here. I then also have to add a line into the SaveViewModule to get the saved value.
Code:
m_SaveContentText.text = basicSaveMetaData.TimePlayed;
My problem is that it is always displaying the GameManager value, and not the value that is saved into the meta data file. I'd love to see an example of the proper way to save/recall a simple value!
Thanks!