The problem that I am having is that I want to read from the actual text asset “Dialogue” rather than just getting its name and loading from the top of the project folder hierarchy.
Is there a way to do this without changing too much code?
EDIT: Solved but more problems below
I now have that set up and everything is working beautifully. I have another question if you don’t mind answering. Whenever I edit a .txt file in visual studios unity no longer will let me drop it in the inspector as a text asset and will proceed to open the file in notepad instead if I try to reopen it again. How can I fix this?
Unity uses the operating systems default file associations, so if a .txt file opens in notepad, thats because .txt files are associated with notepad on your system. You could change this to visual studio if you wanted, but then all .txt files you open on your system will open with vs.
I don’t understand what you mean by “unity no longer will let me drop it in the inspector as a text asset”?
I am just as confused. Whenever I hit save in VS the text file is no longer recognized as a text asset and cannot be dropped in the inspector as such. The file also loses its preview when I just click on it in the folder. When I try to open the text asset again by double clicking it from the “Streaming Assets” folder of my project, rather than defaulting to VS it opens up in notepad.
Upon further investigation I noticed that if I moved a text file from my desktop to the “Resources” folder the file behaves but If I do the same but move it to the “StreamingAssets” folder the file is not recognized. When I move a file from “Resources” to “StreamingAssets” the file is not longer recognized and if I try moving it back to the “Resources” folder the file is still unrecognized.
I don’t think this is a bug, I think its by design.
StreamingAssets is meant to be used for raw files that are copied to your build verbatim. You then load them via script. Since the contents of the file are copied directly, they don’t actually get included in the build. Since they aren’t included in the build, you can’t reference them in a scene.
If you want to use a scene reference, take it out of streaming assets, and treat it as a TextAsset. Otherwise put it in streaming assets and treat it as a file.
why can’t the official documentation be as straightforward as you. This actually explains a lot and tells me that my “workaround” from before is actually what I needed to do. I am still confused as to why this worked on Steego’s end.
Just to be clear here - the files are included in builds! They’re just not imported by Unity in any way. But stuff you put in StreamingAssets when you build are still in the folder after the build.
@Collin_Patrick_1 , if you want to work with text files as TextAssets, just put them in a normal folder (not StreamingAssets or Resources).