Since Unity does not provide a way to disable its automatic import of files such as Blender’s .blend
files, I thought I’d try to find a workaround that would still allow me to keep these files inside a Unity project’s Assets/
folder.
Why Not Use Automatic Import?
As I mentioned in the previous article (
A Custom glTF Importer for Unity), Unity will launch Blender with a custom Python script each time it needs to re-import a .blend
file. The Python script then tells Blender to export the model to a temporary FBX file. Unity then imports the FBX file using its internal importer. This process can get quite slow depending on the number and size of your Blender files, and it doesn’t support having multiple root objects inside a single Blender file which can be pretty useful at times.
Keep in mind this issue applies to other auto-imported assets such as Maya .mb
files or 3dsMax .max
files. For any of these to be imported properly, each user must have a copy of the software required to open them which can get pretty costly.
Why Not Move Files Outside the Assets Folder?
One solution is to simply place all files that should not be auto-imported outside the main Assets/
folder. This may seem like a valid approach, but it makes finding these files more difficult and Unity’s Project window can no longer be used to easily open the files. Unity’s integrated version control will also likely not work with these files.
Out Current “Solution”
Ideally Unity would add a project setting to disable auto-import for specific file types, but until then the best solution that I’ve been able to come up with is to simply use a different file extension. For example, I rename Blender files that normally use a .blend
extension to use a .blender
extension. In Windows it is then possible to map .blender
files to always open with Blender. This is done by right-clicking a .blender
file in Windows Explorer, selecting “Open with…”, picking Blender, and checking “Always use the app to open .blender files”. Windows and Unity’s Project window will then show the correct icon for files with this extension and use Blender to open them.
One important thing to note is that after doing this and renaming existing .blend
files previously imported into Unity, all .blend.meta
files should be deleted (and regenerated) as this is required for the Blender icon to display properly in Unity. Obviously this is best done after switching to a different model format such as .gltf
or .fbx
as it will break all references to the .blend
files.
Updating Git’s .gitattributes
For those using Git for version control, be sure to add an entry to your
.gitattributes
file so that .blender
files will be handled properly by Git-LFS:
*.blender filter=lfs diff=lfs merge=lfs -text
Additional Improvements
To make it easier for other team members to setup file associations, it should be possible to create a registry settings file with all desired extensions. Keys for file associations can be found here and exported to a .reg
file for others to import:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\
Another simple improvement was to add a new item to the Project window’s context menu that allows the user to easily create a new Blender file with the proper extension. This is done inside a custom CreateExternalAsset.cs script that prompts the user to name a new file and then copies a “template” file from a specified directory to the desired filename. The script then launches the associated application with the new file.
This script can easily be extended to create menu items for multiple Blender templates or any other asset type. For example, I also use it to create customized script files for structs, classes, and enums.