- Home /
How can I load an custom file from the Assets folder?
I have raw files that I have built a custom serializer for. All I want to do is to be able to load the files from the game. (They need to be part of the game itself (not saved/loaded from the user's local files))
Answer by Snubber · Mar 16, 2021 at 03:35 PM
Okay I found a really hacky solution. If you put the file extension .txt at the end of the file name you can import the file as a text file. Then in your MonoBehavior create add a TextAsset
property:
public TextAsset _textAsset;
Then you can access the file's bytes with:
_textAsset.bytes;
I hate this solution but it works.
Okay I have learned from https://docs.unity3d.com/Manual/class-TextAsset.html that you can also use the extension .bytes
which makes me feel slightly better.
Okay I have learned from https://docs.unity3d.com/Manual/class-TextAsset.html that you can also use the extension .bytes
which makes me feel slightly better.
Answer by undevable · Mar 16, 2021 at 02:24 PM
Two Methods to Load a File to the Assets Folder:
Method 1:
Right Click on the Assets Section of Unity
Select "Import File"
Select your File
Method 2:
Open File Explorer if you're on Windows, or Finder if you're on Mac
Drag the file from File Explorer/Finder into the Assets Section of Unity
Hope this helps
I meant load a file with code from the Assets folder. I know how to drag and drop files :)
Oh, I'm sorry. Is the file a C# file? If it is I think you should be able to load it like normal