Converting a new file type to assets

I have custom scripts as text files in my project’s assets. These are text files for a custom interpreter, not MonoBehaviour “scripts” per Unity parlance. I can assign the paths to these scripts to MonoBehaviours in the editor, but this path won’t be found at runtime. Can I do something to make these scripts more like other, regular assets instead of putting them in Resources or StreamingAssets?

I just need the text inside of them, although I would like to eventually precompile them into my interpreter’s byte code before “assetifying” them. I just don’t see anything obvious searching for creating a new asset type.

I first thought a ScriptedImporter might do it, but whatever I did isn’t letting me drag-and-drop the script file itself into a MonoBehaviour expecting a ScriptableObject created by my ScriptedImporter. After some more reading, I thought that this isn’t even the right approach.

For now, I’m just settling on loading them as resources, but I figured there was a way to do this.

Change the file extension to .txt and use TextAsset.

It’s not the answer I want but probably the answer I deserve. I do want to create my own asset type for this eventually because the script does get compiled into an intermediate form and I’d like to have the intermediate form be what I’m ultimately carrying around. Otherwise, I’m compiling these scripts at run time.

For what it’s worth, making the scripts basic TextAssets did get the included in the project enough that they’re found properly in the game build.

Look up custom importers. You can use them to create import processors for specific file extensions, and store additional metadata for the imported assets as well, so you can store the compiled byte code for your custom scripts and such in the library, just like Unity stores things like imported texture and mesh data.