#StreamWriter and Better Streaming Assets
1 messages ยท Page 1 of 1 (latest)
What is the stack trace actually pointing to
It's an issue with a call to GetFiles
you are passing a file path to something that expects a directory
- Use
/as path delimiter - Use relative path
that one is not on me it's a function doing it:
string path = BetterStreamingAssets.GetFiles($"Levels/{levelInfo.levelName}.txt")[0];
and what do you mean by use relative path
but it returns a string which I pass to sw so I don't see where the problem is
and the string is correct as you saw from the screenshot I sent
"Get the files in this directory" and then you pass it a file
ok so you are saying that it's better assets causing the error and not the stream writer.
let me try to get all files and filter them by name then and see if the error is still there
GetFiles searches the directory and give you list of files
And you should not use stream writer to StreamingAssets. It's read only on the build.
So I think your usage itself is wrong ๐ค Use persistentDataPath to save data
what's that?
from what I've read the only persistent data paths are streaming assets and resources and in this case resources are not an option for me
meen I've been asking about this for ages and everybody told me that the only persistent things were asset bundles resources and streaming assets 0_o
thanks a ton for this and let me give it a try
Either they gave the super wrong info or your question was probably misleading
what types of files can you store here?
Any files
well my question was:
I would like to allow users to create custom maps for my games with scripts(which I can see why they wouldn't work without being built in the game), scenes, materials...
for this game I need only text files since I am building my own level editor
StreamingAssets literally built in the game and should not be edited
I see
https://docs.unity3d.com/Manual/StreamingAssets.html
On many platforms, the streaming assets folder location is read-only; you can not modify or write new files there at runtime. Use Application.persistentDataPath for a folder location that is writable.
do I need to create that file in the editor somehow or what?
CreateDirectory ๐
yeah but how, in the streaming assets it was a simple as creating a folder there
Do Directory.CreateDirectory
ok I guess I'll need a script for creating a new level then but that's not a problem, let me try to work this out and thanks a ton you saved me a lot of time
actually wait, is there a way to create this directory when the game is being installed or ran for the first time so I don't have to check if the directory exists every time I am running the game?
I am aware that I can make a custom installer but that wouldn't work for android and this game is mainly targeted for phone users
Use google pls. I gave you method. https://docs.microsoft.com/en-us/dotnet/api/system.io.directory.createdirectory?view=net-6.0
Creates all directories and subdirectories in the specified path unless they already exist.
yeah I will find out how to use that method what I asked is if it was possible to do something on the first game run only or something like that but it's ok if you don't have time figuring that out for me
lol
Read what I quote? Creates unless they already exist.
I did read it and that's not what I was asking I asked this in case I ever needed something only for the first time because I am still learning
but as I said it's all good and you don't have to help me with that I am already thankful enough for this because it saved this and one more project I was working on so thanks for that
Add flag to PlayerPrefs if it's first run. But then that is already checking something anyways.
There is no built-in isFirstRun or whatever and if such thing exists it is checking something too.
No difference than check if directory exists.
ok I see, thanks!
Alright good luck with your project