BAsset Documentation

v1.8.0

Read the Docs...

Welcome! This page contains documentation for the BAsset (Blender Asset) 'prefab' format for the Unity game engine and the BAsset Exporter Addon for Blender.

Use the navigation panel on the left to quickly jump between sections.

If you prefer watching to reading, check out the features demo video, which covers everything documented here:

BAsset Tools: Design Unity Prefabs in Blender

Download and Install

The addon can be downloaded from its Gumroad Page.

In Blender, select Edit->Preferences, click on the Addons tab, click Install and open the file: djh_basset_exporter.zip.

In Unity, select Assets->Import Package->Custom Package... and open the file: djh_basset_importer.unitypackage, or drag and drop the package into your Unity project.

Overview

Why do I want it?

Out of the box, Blender offers many advanced tools for arranging 3d objects in a space beyond what is easily achievable in Unity.

You can use geometry nodes to scatter clumps of grass, procedurally arrange doors and windows around a building, or run a physics sim to see how objects might come to rest on the ground.

But there's a limitation, a game can't have every beam, wall, or blade of grass be a custom mesh...we want to reuse and instance assets.

The BAsset tools allow you to export an arrangement of objects from Blender and recreate the arrangement with prefabs in Unity.

image_05

Blender Exporter

User Preferences

Enable the addon by searching for 'BAsset' in the 'Addons' tab of the Blender Preferences dialog.

image_01

The addon has two additional settings:

Mesh Export Path: defines a folder on your computer where quick-export .fbx files will be saved.

Asset Export Path: defines a folder on your computer where .basset (json) 'prefab' files will be saved.

BAsset Export Panel

The BAsset Export Panel is located under the DJH tab of the 3D View's Sidebar (N Panel) in Blender.

image_02

The Name field lets you edit the object-data name, which is used when quick-exporting a .fbx file.

The Export FBX Asset button exports a .fbx file in a single click. The selected objects will be exported and the .fbx file name will match the name of the active object in Blender. The .fbx file will be saved in the Mesh Export Folder, defined in the BAsset Addon Preferences. The text above the button is a preview of the export filename.

The Name field lets you define the name to use when exporting a .basset file.

The Export {name}.basset button exports the selected objects as a .basset JSON file. The names of the selected objects and all the objects that are instanced by the selected objects are exported along with their transforms. To import correctly, prefabs or meshes with the same names must exist in your Unity Assets folder.

Blender objects whose names begin with an underscore are ignored by the exporter, but any instances that they spawn are not ignored. This allows you to choose whether an object that spawns instances is exported along with its instances or not.

Unity Importer

The Import options will appear in the Unity Inspector after selecting a .basset asset file.

image_03

The Instances setting allows you to customize which GameObjects/Prefabs are spawned for each instance name defined in the BAsset file.

If you want to reset a modified Instances list, you can force the BAsset to reset and search for matching prefabs by setting the instances array length to 0 and clicking apply.

image_04

The BAsset importer will create a prefab in the Collections folder when importing the .basset file. Due to limitations imposed by Unity, it is not possible to save the prefab within the .basset file and to maintain links to child prefabs. Those links are important because we want changes to the instanced child prefabs to also apply to and be reflected in the .basset collection.

image_10

The BAsset Folder

image_08

In your Unity project I recommend keeping everything organized in one folder:

BAssetthe BAsset root folder
-_scriptscontains the editor scripts for importing .basset files
-collectionsintended for prefabs created from .basset files
-fbxintended for .fbx files exported from Blender with the quick export button
-jsonintended for .basset files exported from Blender with the BAsset export button
-prefabsintended for prefabs created from .fbx files

Prefab Selection

When importing a .basset, the importer will search your assets database for prefabs or fbx assets with names that match the instances defined in the .basset file.

The importer will always choose a prefab over a .fbx if the option is presented.

Copy to Prefab

A 'Copy to Prefab' option has been added to the Assets context menu, it allows you to create a prefab for each selected .fbx file. The created prefabs will have the same name as file they were created from and will be placed in the INSTANCES folder.

image_06

The folder paths are defined in the settings section of the import script. By editing the constant values at the top of the script you can configure it according to your preferences.

image_07

File Format

BAsset files are a JSON array of instance names, each of which have an array of transforms.

image_09

© 2023-2024 Daniel Hickox