Answer the question
In order to leave comments, you need to log in
Unity how to store json in given code?
Good day. Tell me, does JSON save the parameters of the object to which the script is attached, or all the variables from the script itself?
public Vector3 LastPosition = Vector3.zero;
public Quaternion LastRotation = Quaternion.identity;
private Transform ThisTransform = null;
void Awake()
{
ThisTransform = GetComponent<Transform>();
}
void SaveObject()
{
//create output path
string OutputPath = Application.persistentDataPath + @"\ObjectPosition.Json";
LastPosition = ThisTransform.position;
LastRotation = ThisTransform.rotation;
//Generate Writer Object
StreamWriter Writer = new StreamWriter(OutputPath);
Writer.WriteLine(JsonUtility.ToJson(this));
Writer.Close();
Debug.Log("Outputting to: "+OutputPath);
}
Answer the question
In order to leave comments, you need to log in
What you give is what you keep. JsonUtility.ToJson(this)
will save the "parameters" (public fields and those marked with the attribute [SerializeField]
, what is visible in the inspector) of the class, a piece of which you have shown.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question