Assets
How the NEO engine loads files such as models, images, sounds and data into your game, and the pages that cover each part of the asset system.
An asset is data your game loads from a file or makes at runtime: a mesh, an image, a sound, a glTF model, an animation clip or your own data type. The engine's asset system reads the file in the background, turns it into a Rust value and stores it, and your code refers to it through a small handle.
This section is for creators who write Rust game code. For how the Studio uploads and stores your game's files on NEO, see Assets.
How it fits together#
| Part | What it is |
|---|---|
AssetServer | A resource that starts loads. asset_server.load("models/crate.glb#Scene0") returns a handle straight away and loads in the background. |
Handle<T> | A reference to an asset of type T. It keeps the asset alive while any strong handle exists. |
Assets<T> | A resource holding every loaded asset of type T. Look an asset up with its handle. |
AssetEvent<T> | A message sent when an asset is added, modified, removed or fully loaded. |
AssetLoader | Turns bytes into an asset. The engine has loaders for glTF, images, audio, fonts, shaders and world files; you can add your own. |
| Asset source | Where bytes come from: the assets/ folder by default, or another folder, embedded data or a custom reader. |
src/main.rs
use neo::prelude::*;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_systems(Startup, setup)
.run();
}
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.spawn(Camera2d);
// loads assets/textures/crate.png in the background
commands.spawn(Sprite::from_image(asset_server.load("textures/crate.png")));
}Pages in this section#
| Page | What it covers |
|---|---|
| Loading assets | AssetServer::load, paths and labels, load states, folders and loader settings. |
| Using assets | Assets<T>, handles and ids, asset events, adding and changing assets at runtime. |
| Hot reloading | Reloading assets when their files change, and reloading by hand. |
| Custom assets and loaders | Your own asset types, the RON loader and writing an AssetLoader. |
| Asset processing | Processing assets ahead of time with .meta files, transformers and savers. |
| Asset sources | Extra folders, embedded assets and how NEO games find their content. |
| glTF | Loading glTF models, their labels, materials and extras. |
What's on in NEO's builds#
NEO games build the engine with its default features. A few asset features are off:
| Feature | What it adds | In NEO's builds |
|---|---|---|
file_watcher | Hot reloading from the file system | Off |
asset_processor | Processing assets ahead of time | Off |
jpeg, bmp, tga, webp, ... | More image formats | Off. PNG, HDR and KTX2 are on. |
http, https | Loading assets from web addresses | Off |
mp3, flac, wav | More audio formats | Off. Ogg Vorbis is on. |
See Cargo features for turning features on.