I’ve recently started to include a save and load system using this youtube channel’s as a guide:
However I have hit a wall for some time now where I don’t know if this is a legitimate error when I close my app in the unity simulator:
System.UnauthorizedAccessException: Access to the path ‘C:\Users\user\AppData\LocalLow*user\app*’ is denied.
at 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) [0x000e0] in :0
at System.IO.FileStream…ctor (System.String path, System.IO.FileMode mode) [0x00000] in :0
Error debug gives the following
Debug.LogError("Error occured when trying to load data from file: " + fullPath + “\n” + e);
Error occured when trying to save data to file: C:/Users/user/AppData/LocalLow/user/app
Has anyone come across this before? I noticed the error uses forward slashes compared to the debug which uses backwards slashes. Is that something?
Did you modify that path before posting, or is this what you used in code?
In the latter case the logged in user would have to be named “user” and at the end the “user\app” part may also not be correct. Looks like placeholders you are supposed to replace with actual folder names.
Also take note that if you want your app to be compatible with non-Windows platforms you should use forward slashes in paths, or run each path string through Path.GetFullPath(path) to normalize it.
I had the same problem with this tutorial, but I checked out the package included on the tutorial’s GitHub, and found that he’d made a bunch of updates to the script files after the video was made. For anyone else who runs into this and just followed the tutorial, I would recommend comparing the tutorial project files to the final, and incorporating the updates, and it should work after that.
In the end, my desire to move on won out over my desire to learn how to do everything myself, and I just bought the EasySave3 plugin from the AssetStore. $60, but worth every penny for the stress it relieved.
You really don’t need to fuss with FileStream and StreamReader/Writer unless you’re doing partial file reads or other low level control over the process.
Otherwise just use File.Read/WriteAllText/Bytes for your bog standard read/write operations. Naturally Applicaton.persistentDataPath should be used to start your file path for save files.