Linking assets
Introduction
The editor provides a way to use assets directly in scripts. Those assets are preloaded and are part the loading process of the scene.
To use those assets in scripts, properties need to be decorated with the @visibleAsAsset decorator from the babylonjs-editor-tools package and will then be available in the editor's inspector.
To set those properties, simply select an asset from the Assets Browser panel and drag & drop it to the desired property in the inspector.
To set those properties, simply select an asset from the Assets Browser panel and drag & drop it to the desired property in the inspector.
If the dropped asset is not compatible with the property type, an error popin will be displayed.
The supported asset types are:
- json: any JSON file that can be parsed.
- material: any material created in the editor and available as asset.
- gui: any GUI created in the editor and available as asset.
Those decorators are available in the babylonjs-editor-tools package that is provided as a depdendency in the package.json file. In case a decorator that is documented here is not available in the code, make sure to install the up-to-date package in your project.
JSON files
When a property is decorated with @visibleAsAsset, this property will be linked to the provided asset with extension .json in the editor's inspector. The JSON file is automatically parsed and properties can be accessed directly.
Material files
As well as JSON files, when a property is decorated with @visibleAsAsset, this property will be linked to the provided asset with extension .material in the editor's inspector. The material is automatically parsed and properties can be accessed directly.
In order to restrict the type of supported material, a configuration object can be passed to the decorator. By default, all materials are allowed. Example to restrict to PBR material:
GUI files
As well as JSON files, when a property is decorated with @visibleAsAsset, this property will be linked to the provided asset with extension .gui in the editor's inspector. The GUI file is automatically parsed and properties can be accessed directly.
Next
Using Sprite Manager