How can I load an custom file from the Assets folder?

I am making a voxel building game (like Minecraft). I wrote a custom serializer that can turn my voxels into a byte array (and vice versa, turn a byte array into voxels (and generate the GameObject with the mesh etc.)).

I want to be able to load one of these files into the game and I want to have these files be a part of the game build so when anyone loads and plays the game they also load in the same voxel structures. So I think I want these in the Asset folder? In an ideal world I could just put these files in the Asset folder and then drag them onto a Component or ScriptableObject. But I can’t figure out how to do that.

I also tried making a custom ScriptedImporter. It works like a charm except the GameObject that is created by the importer script does not save the variables within it’s components. So I can import the voxel file into a GameObject and generate the voxels mesh. But when I use it in game the voxel data is not saved and I run into errors when I try and edit the voxels.

Maybe Resources.Load would work but it seems that it only loads Unity Objects.

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:


I hate this solution but it works.