I'm using UnityWebRequestTexture to load images from my file system into my game. Here is my code:
private IEnumerator ImageLoadCoroutine(int i)
{
GameObject imgObj;
Texture2D imageTex = null;
//string activeDir = fileList[i];
//activeDir = activeDir.Replace("+", "+"); // Does not fix issue!
//using (UnityWebRequest uwr = UnityWebRequestTexture.GetTexture(activeDir))
using (UnityWebRequest uwr = UnityWebRequestTexture.GetTexture(fileList[i]))
{
yield return uwr.SendWebRequest();
if (uwr.isNetworkError || uwr.isHttpError)
{
// "+" dirs have HttpError
Debug.Log(uwr.error + "(" + uwr.isNetworkError + ", " + uwr.isHttpError + ")");
}
else
{
// Get downloaded asset bundle
imageTex = DownloadHandlerTexture.GetContent(uwr);
}
}
imgObj = Instantiate(imagePrefab);
imgObj.transform.SetParent(imageContainer.transform);
imgObj.transform.localPosition = Vector3.zero;
imgObj.transform.localRotation = Quaternion.identity;
imgObj.transform.localScale = Vector3.one;
imgObj.GetComponent().texture = imageTex;
imgObj.GetComponent().enabled = false;
imgObj.GetComponent().enabled = false;
imagesLoaded++;
imageList[i] = imgObj;
}
However, when I try to load images from directories containing the '+' or '#' characters (i.e. "C:\Users\MyUser\Documents\Unity Projects\The+++Folder"), I get the HttpError: "HTTP/1.1 404 Not Found"
Directories containing other special characters like @, &, or = work fine. Using the Replace function to replace the characters with their character entity reference code (i.e., replacing all instances of "+" with "& plus ;") did not fix the problem.
What is the source of this issue, and is there a way around it? I'd rather not be arbitrarily restricted in which valid folder names actually work with my program.
Thanks!
↧