Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Bundles

Scripts can insert bundles defined in Rust, all components at once:

FunctionBehaviour
world.insert_bundle(entity, type, value)Inserts the bundle’s components into the entity.
world.spawn_bundle(type, value)Spawns an entity with the bundle and returns it.

Bundles need ReflectBundle type data, and are constructed like any other type:

#[derive(Bundle, Reflect, Default)]
#[reflect(Bundle, Default)]
struct EnemyBundle {
    health: Health,
    transform: Transform,
}

app.register_type::<EnemyBundle>();
// tuples and foreign bundles: app.register_type_data::<(Health, Transform), ReflectBundle>()
local world = import_namespace("bms").world
local EnemyBundle = import_namespace("my_game").EnemyBundle
world.spawn_bundle(EnemyBundle, EnemyBundle.new({ health = Health.new({ hp = 10 }) }))