I'm trying to load a class using JsonUtility
to populate a few strings. I navigate to the file using Unity Simple File Browser and load it using the following coroutine:
IEnumerator ShowLoad()
{
yield return FileBrowser.WaitForLoadDialog(FileBrowser.PickMode.Files, false, null, null, "Upload", "Select");
if (FileBrowser.Success)
{
Debug.Log("File Browsed: " + FileBrowser.Result[0]);
UnityWebRequest url = new UnityWebRequest("file:///" + FileBrowser.Result[0]);
yield return url;
StreamReader reader = new StreamReader(url.ToString());
string json = reader.ReadToEnd();
Campaign c = JsonUtility.FromJson<Campaign>(json);
CampaignName = c.CampaignName;
saveFolder = c.saveFolder;
savePath = c.savePath;
persistentFolder = c.persistentFolder;
persistentPath = c.persistentPath;
}
}
But every time I try to run the code I get the following error:
FileNotFoundException: Could not find file "C:\Users\arily\Documents\GitKraken\DND-Astra\Astra\UnityEngine.Networking.UnityWebRequest"
System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share, System.Int32 bufferSize, System.Boolean anonymous, System.IO.FileOptions options) (at <7b935204f5ff4bcab44b3b0ebca330bf>:0)
System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share, System.Int32 bufferSize, System.IO.FileOptions options) (at <7b935204f5ff4bcab44b3b0ebca330bf>:0)
(wrapper remoting-invoke-with-check) System.IO.FileStream..ctor(string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare,int,System.IO.FileOptions)
System.IO.StreamReader..ctor (System.String path, System.Text.Encoding encoding, System.Boolean detectEncodingFromByteOrderMarks, System.Int32 bufferSize) (at <7b935204f5ff4bcab44b3b0ebca330bf>:0)
System.IO.StreamReader..ctor (System.String path, System.Boolean detectEncodingFromByteOrderMarks) (at <7b935204f5ff4bcab44b3b0ebca330bf>:0)
System.IO.StreamReader..ctor (System.String path) (at <7b935204f5ff4bcab44b3b0ebca330bf>:0)
(wrapper remoting-invoke-with-check) System.IO.StreamReader..ctor(string)
Campaign+<ShowLoad>d__12.MoveNext () (at Assets/Campaign.cs:90)
UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at <ab7de6937a4448b0a6ccd59e9820599a>:0)
I have tried the same method using WWW
to load an image and it worked, but when loading a JSON using WWW
I get the same error referring to UnityEngine.WWW
instead. I haven't been able to find anything online about it, so I'm posting here. Any insight or tips would be much appreciated, thank you!