- Home /
The question is answered, right answer was accepted
DirectoryNotFoundException with full existing path... ? How can this be? I need an answer ASAP
So, I'm getting this HUGE error, and I don't really know what to do about it...
DirectoryNotFoundException: Could not find a part of the path "C:\Users\multi\Desktop\Project P\Assets\StreamingAssets\Saves\A New Game\game_manager.json". System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean anonymous, FileOptions options) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.IO/FileStream.cs:292) System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share) (wrapper remoting-invoke-with-check) System.IO.FileStream:.ctor (string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare) System.IO.StreamWriter..ctor (System.String path, Boolean append, System.Text.Encoding encoding, Int32 bufferSize) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.IO/StreamWriter.cs:124) System.IO.StreamWriter..ctor (System.String path, Boolean append, System.Text.Encoding encoding) (wrapper remoting-invoke-with-check) System.IO.StreamWriter:.ctor (string,bool,System.Text.Encoding) System.IO.File.WriteAllText (System.String path, System.String contents, System.Text.Encoding encoding) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.IO/File.cs:626) System.IO.File.WriteAllText (System.String path, System.String contents) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.IO/File.cs:621) GameManager+c_Iterator0.MoveNext () (at Assets/GameManager.cs:123) UnityEngine.SetupCoroutine.InvokeMoveNext (IEnumerator enumerator, IntPtr returnValueAddress) (at C:/buildslave/unity/build/Runtime/Export/Coroutines.cs:17) UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator) GameManager:LoadGame() (at Assets/GameManager.cs:89) SavesLoader:m_0() (at Assets/UI/SavesLoader.cs:63) UnityEngine.EventSystems.EventSystem:Update()
Eh... Could someone help me please? The path exists, and there is no reason for it to not save the file... This is how I save my files:
string newFile = JsonUtility.ToJson(managerJSON);
File.WriteAllText(SaveDirectory + "game_manager.json", newFile);
For some reason my "A New Game" folder is read only. does this mess with my system for some reason? Thanks in advance.
Answer by Igor_Vasiak · Mar 07, 2018 at 09:51 PM
Found the solution:
string newFile = JsonUtility.ToJson(managerJSON);
System.IO.FileInfo file = new System.IO.FileInfo(SaveDirectory + "game_manager.json");
file.Directory.Create();
System.IO.File.WriteAllText(file.FullName, newFile);
You can find it here.
I'm a pretty new Unity User -- I'm having the same error but I'm not sure where I would type in these commands. Where do you type this in?
Follow this Question
Related Questions
how to fix the "unityexception : launching ios project via xcode failed" exception ? 0 Answers
Saving object references into json breaks on restarting the editor 0 Answers
Package directory not found for DataContractSerialization 1 Answer
SSLHandshakeException during Web Request 0 Answers
Destroying Components from Editor Script Throwing MissingReferenceException 1 Answer