If you haven’t been using the binary formatter and instead opted to use the Json save system that Brian provided here: Home · Wiki · Brian K. Trotter / RPGMods · GitLab, then you should be able to change the class as follows:
public JToken CaptureAsJToken()
{
Dictionary<string, JToken> data = new Dictionary<string, JToken>();
data["position"] = transform.position.ToToken();
data["rotation"] = transform.eulerAngles.ToToken();
JToken returnToken = JsonConvert.SerializeObject(data);
return returnToken;
}
public void RestoreFromJToken(JToken state)
{
if (navMeshAgent == null)
{
navMeshAgent = GetComponent<NavMeshAgent>();
}
JObject jsonObject = JObject.Parse(state.ToString());
Dictionary<string, JToken> myDictionary = jsonObject.ToObject<Dictionary<string, JToken>>();
navMeshAgent.enabled = false;
transform.position = myDictionary["position"].ToVector3();
transform.eulerAngles = myDictionary["rotation"].ToVector3();
navMeshAgent.enabled = true;
GetComponent<ActionScheduler>().CancelCurrentAction();
}
Just as a note, I had to reset the navMeshAgent here as I got null reference errors occasionally.
This seemed to work for me. I hope it is correct and helps someone else out if they need it.