- Home /
One Unity instance writes to a text file, while the other reads the text file
I need to have two Unity instances open simultaneously (not executables, but both in Editor mode), one keeps writing data to a local text file, while the other keeps reading content in that text file.
Mainly I am using FileStream to do StreamWriter and StreamReader. But I keep getting this error: "IOException: Sharing violation on path: C:\myfolder\position.txt". Obviously the two Unity instances are fighting for file access permission -- if one is reading (writing), the other can't write (read).
I searched for some solutions online, most of them are about having one same script that has both StreamWriter and StreamReader, and the script is running in one single instance of Unity. I tried to apply this solution to my two Unity instances but it didn't work. I was still getting the same error.
Could you share some suggestions? Thanks. (Doesn't have to be FileStream...whatever works for this concurrent reading/writing on two Unity instances.)
Answer by tanoshimi · May 17, 2016 at 05:58 AM
I don't think this is a Unity problem - it's a limitation of your filesystem - you can't generally have any file (jpg, doc, mp3, whatever) simultaneously being accessed by two different processes on your system. This is to maintain the integrity of the file contents.
What problem are you trying to solve? Why not have a Daemon service running that holds your data in memory and only saves it back to a file when your processing is done?
Tanoshimi, thanks for your response. I wrote a earlier post on StackOverflow to describe what I was trying to do: http://stackoverflow.com/questions/37018195/vuforia-unity-communicating-between-2-unity-64-32-bit-instances
Hopefully that post gives you an idea about what I am trying to do. Network$$anonymous$$anager in Unity is not working well with Vuforia. That's why I thought I should come back to the original method of reading/writing a text file locally and simultaneously with two Unity instances.
Your answer
Follow this Question
Related Questions
Is it possible to give a color to int variables? 1 Answer
Long string for dialog text 1 Answer
Ui text to string ? 1 Answer
Text UI broken after changing alpha color of single letters 1 Answer
[SOLVED] Why is text not appearing? 2 Answers