0

I'm trying to Save and Load Vector3 Coordinates in HoloLens App the program works on my laptop using unity but it will not save or load a file in the HoloLens. Here is the program I am using to create the path for saving and loading. Any help would be appreciated.

    public GameData Load()
    {
        string fullPath = Path.Combine(dataDirPath, dataFileName);
        GameData loadedData = null;
         if (File.Exists(fullPath))
         {

            try
             {
              string dataToLoad = "";
                using (FileStream stream = new FileStream(fullPath, FileMode.Open))
                {
                    using (StreamReader reader = new StreamReader(stream))
                    {
                        dataToLoad = reader.ReadToEnd();
                    }
                }

                loadedData = JsonUtility.FromJson<GameData>(dataToLoad);

            }
            catch (Exception e)
            {
               UnityEngine.Debug.LogError("Error occured when trying to load data from filr: " + fullPath + "\n" + e);
            }
    
         }
       return loadedData;
        
    }

    public void Save (GameData data)
    {

        string fullPath = Path.Combine(dataDirPath, dataFileName);
        try
        {
            Directory.CreateDirectory(Path.GetDirectoryName(fullPath));

            string dataToStore = JsonUtility.ToJson(data, true);

            using (FileStream stream = new FileStream(fullPath, FileMode.Create))
             {
                using (StreamWriter writer = new StreamWriter(stream))
                {
                    writer.Write(dataToStore);
                }
             }
         }
        catch (Exception e)
         {
            UnityEngine.Debug.LogError("Error occured when trying to save data to file: " + fullPath + "\n" + e);
         }
    }

}
bb1121
  • 11
  • 1

1 Answers1

2

If I understand this correctly, you're debugging remotely. To clarify, your application cannot access files on HoloLens until you deploy it to HoloLens. And for how to access files on HoloLens, you can refer Create, write, and read a file - UWP applications | Microsoft Learn and Working with File on Hololens 2 (UWP to .NET).