Have Unity Support Your Custom File! (Part 1/6)

Miijii
Miijii’s Unified Works
5 min readFeb 28, 2023

A cool trick for those wanting to add their own file extension inside the Unity Game Engine.

A Unity Game Project displaying an .xvnml and the XVNML Importer (on the right).
A Unity Project with a selected asset called “MainProxySample.xvnml”

You heard right! This is no lie. Using Unity, we going to have it import any kind of file type that we want (either a .rtx, .rll, or in my case, a .xvnml), and have it display an icon for it that stays persistent when you enter and leave the editor. Not only that, but we’ll have our custom files include with our Unity Build without the need to put the file inside the StreamingAssets folder.

What’s cool about this particular Unity trick is that it’s VERY easy to achieve, and you can use what you learn in this article to improve your Game Developing Workflow!

Hi! My name is Miijii (it’s a Pen-Name). I’ve been making games for 10 years; using Unity as my game engine of choice for 5 years. The purpose of this 6 part series is due to me working on a duel-project (that being XVNML and XVNML2U). Sometimes, when I’m searching up how to do something on the internet, the search results doesn’t necessarily take me to where I need it. Not only that, but when it does, and I try a certain method, it seems to not turn out the way I want it. This is to not only share parts of my hardships towards developing XVNML and XVNML2U, it’s a perfect opportunity to documentate and publish the thing that I’ve learned that may improve the way someone makes a game (or works on a project in general). I like to find ways to improve my Game Development workflow, so I’ll be using this media platform to share a lot of my knowledge with everyone. Also, this is a perfect way to make content while I try getting my Youtube channel together.

This will officially be the first blog post that I’ve made using this platform. If later on through this 6 part series you enjoyed or learned something from this content, please consider supporting me as I begin my online blogging journey (and more). I’m always open to constructive criticism, and if there’s information that I may have missed or didn’t explain properly, please let me know.

Before we get into how we tell Unity to import our desired file of a specified extension, it’s best for us to rack up knowledge on what files the Unity Game Engine official supports out of the box. Per Unity’s Official Documentation, Unity’s supports a full range of different file types. Those supported asset types include:

  • 3D Model Files (.fbx, .dae (Collada), .dxf, .obj)
  • Image Files (.bmp, .tif, .tga, .jpg, and .psd)
  • Audio/Tracker Module Files (.wav, .mp3, .ogg, .aiff, .aif, .mod, .it, .s3m, .xm)
  • Text, HTML, XML, and JSON
  • Plugins and Code-Related Assets (.dll, .asmdef)
  • Native assets (animations, curves, gradients, masks, materials, presets)

Out of all of these, only a few are not included when you create a Unity Build without placing them in the “StreamingAssets” folder (which needs to be created; Don’t worry, Unity will know what to do with this folder). Those files are your Text, HTML, XML, and JSON assets.

In most cases, when someone creates a custom file extension (for example: TestCube.cube), it’s usually a glorified version of either XML, YAML, or JSON (Fun Fact: A Unity Scene is actually a YAML file!). Give it a try: in your File Explorer, go into your Unity Project’s directory. Go to Asset, and find a scene. If you don’t see a scene, go ahead and create one in the Unity Editor. Still in the File Explorer, right click of your scene and in the sub menu select “Open With”. You want to select “Choose Another App” and open it with any text editor you want (notepad is fine if you just have that).

Displaying internal contents of “CustomTagScene.unity”

In Unity, those files are imported as TextAssets. When you drop any sort of text file into the Unity Asset’s folder, it uses an Importer to take that file and turn it into something tangible that Unity can actually use and include into the final build. Below is an image of a .cs.txt file being inspected and shown as a TextAsset. This sort of file is used for Templated Scripts (which is what we’ll be learning in this article to do our magic. Just not this one in particular).

Another important subject that I forgot to mention involved Unity’s native assets. One of the most common native file types that you’ll find inside your Unity project is a .asset file. These files are mostly (if not always) associated with a very neat Unity feature that til this very day is the coolest feature: ScriptableObjects.

A folder containing 1 folder and 2 assets, one being a Scriptable Object, another a Prefab.
A Scriptable Object in the Middle

When it comes to custom user data that can not only be accessed, modified, and remain persistant, but also beinclude with your Unity build, the concept of creating ScriptableObjects is one of the most important Unity subject you must learn to make use out of this engine. That’s how good it is.

So, why is it important to know all of this before hand? Since we’re creating an new Asset that’ll behave much like Unity’s supported asset types, it’s important to know how Unity takes a file of a certain type or extension, imports it, and includes that information when you go to your Build Settings and click “Build”. For a more in-depth explanation of Unity’s Asset Workflow, click here.

In this series on how you can import any file type in Unity, we’ll be going through each of the following subjects in great detail:

That way, even if you don’t completely finish reading through all of this material, you’ll at least learn one of the subjects discussed in this series. And by the end of it all, you’ll be able to use these things outside of just having a custom file be importer and used by the Unity Game Engine. I guarantee that this article (in some way, shape, or form), will change the way how you approach your Project, and will also help you improve your workflow. More productivity = Happy Camper!

So with that out of the way, let’s learn some tricks!

Click here for Part 2: Scriptable Objects!

--

--

Miijii
Miijii’s Unified Works

Miijii (Pen-Name) | Game Developer | Developing XVNML, XVNML2U, and Tomakunihahaji