Hello, all!
I am a newbie and I am trying to save a list of vector 3 from another script, but I am getting this run-time error:
NullReferenceException: Object reference not set to an instance of an object
Serializer+d__3.MoveNext () (at Assets/Serializer.cs:16)
UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at C:/buildslave/unity/build/Runtime/Export/Coroutines.cs:17)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
using Mapbox.Unity.MeshGeneration.Factories;
public class Serializer : MonoBehaviour
{
static readonly string SAVE_FILE = "player.json";
DirectionsFactory s1;
IEnumerator Start()
{
s1 = gameObject.GetComponent<DirectionsFactory>();
yield return new WaitForEndOfFrame();
string json = JsonUtility.ToJson(s1.output);
string filename = Path.Combine(Application.persistentDataPath, SAVE_FILE);
if(File.Exists(filename))
{
File.Delete(filename);
}
File.WriteAllText(filename,json);
Debug.Log("Player saved at "+ filename);
}
}