My program is getting an invalid character in path error. The path is: D:/Unity/Unity Projects/UnityTest/Assets/User Assets/General/objectList.txt The code reads var sr = new System.IO.StreamReader(path); I have used this code successfully so the problem is in the path string, I can't see any problem with it though. The path is var path = Application.dataPath + "/" + userAssetsFile + "/" + gamesList + "/" +objectListFile; There is also another problem that the string variables aren't updating when I change the string variables for example when I change objectlistFile to be blah.txt the path doesn't change, or it sometimes does but not always. What is going on?
Try debug.logging out the path: var path = Application.dataPath + "/" + userAssetsFile + "/" + gamesList + "/" +objectListFile; Debug.Log("PATH: " + path); Beyond that, I would not be surprised if it does not support forward slashes like that. Try changing them all to backslashes.
Thats what I already did, with your code i get PATH: D:/Unity/Unity Projects/UnityTest/Assets/User Assets/General/objectList.txt the other slashes is simply get PATH: D:/Unity/Unity Projects/UnityTest/Assets\User Assets\General\objectList.txt and still the same error
Notice your other path still has forward facing slashes. Try this: var path = Application.dataPath + "/" + userAssetsFile + "/" + gamesList + "/" +objectListFile; path = path.Replace("/", "\\");
PATH: D:\Unity\Unity Projects\UnityTest\Assets\User Assets\General \objectList.txt ArgumentException: path contains invalid characters Interestingly, var objectListFile = "Object List.txt"; and has done since before I posted this. It is not registering the changes and seems to have some stored copy of the variables in the object the script is attached to, and it is not refreshing when the script asset is changed. Also, if it helps with the diagnosis, when I paste the output into the forum post it puts a random endline in after the word general as above. This I assume is the invalid character but path = path.Replace("\n", ""); doesn't change that.
Thanks a lot man, that solved it. About the object script not updating when the script changes, is there somewhere I should be reporting that as a bug? There is an easy workaround which is simply to delete the script off the object and then add it again, but I am fairly sure this is unintended behaviour.
Yeah, I'm not sure about that. I've never had that issue before. (maybe try giving Unity a few seconds after saving/closing the editor before building/playing the game?)
it's absurd i get this error andin my case if use for example path="data/nomefile.txt" or path="data\\nomefile.txt" inside the source it works (new streamreader(path)) without error, but if i use some simlar to path="data/"+varname+".txt" where varname="nomefile" it give this error. Only when i make path=path.Replace("\r","") it give right result without error. this is for me a BIG BUG that make me lost many time. it's not normal for me....