Okay… so what am I doing wrong?
BIG OL EDIT… I had done a bunch of Undoing and accidentally had the type saving as SV3 and not my type. However… this code still doesn’t seem to care much about rotation. Defaults to pointing east.
Clarity: I am guessing the Euler stuff is just not liking it. Any thoughts what I am being a bonehead on here?
(I’ve even saved JUST the rotation.y as a float and pulled it in that way. Debugging it certainly seems like I’ve forgotten my Quaternion rules)
public object CaptureState()
{
PlayerSave playerSave = new PlayerSave();
playerSave.position = new SerializableVector3(transform.position);
var rot = new Vector3(transform.rotation.x, transform.rotation.y, transform.rotation.z);
playerSave.rotation = new SerializableVector3(rot);
return playerSave;
}
public void RestoreState(object state)
{
PlayerSave playerSave = (PlayerSave)state;
navMeshAgent.enabled = false;
transform.position = playerSave.position.ToVector();
transform.rotation = Quaternion.Euler(playerSave.rotation.ToVector());
navMeshAgent.enabled = true;
GetComponent<ActionScheduler>().CancelCurrentAction();
}
[System.Serializable]
private class PlayerSave
{
public SerializableVector3 position;
public SerializableVector3 rotation;
}