bevy-audio-systems
Installation
SKILL.md
Bevy audio systems
When to use
Load this when a clip should start, loop, pause, or change volume. bevy::audio on docs.rs latest (0.20.0) and the audio_control example there are the sources.
ECS shape
- Play: spawn
AudioPlayer::new(asset_server.load(...)).AudioPlayer<Source>holdsHandle<Source>whereSource: Asset + Decodable. If the asset is not ready, playback starts when it is.AudioPlayerrequiresPlaybackSettings. - Settings:
PlaybackSettingsconfigures the start.PlaybackSettings::LOOPand.with_spatial(true)appear in the spatial examples. Changes toPlaybackSettingsdo not affect audio that is already playing.PlaybackModeisOnce,Loop,Despawn, orRemove. - Control: when playback begins, Bevy inserts
AudioSink. The control example queriesAudioSinkand callspause,toggle_mute,set_volume,set_speed, andposition.SpatialAudioSinkis the spatial counterpart named on the playback page. - Replay: after a non-looping sound finishes and the sink is drained, that
AudioPlayercannot be reused. Remove the audio components and add them again. - Schedule: spawn on
Startupor from a system that hasRes<AssetServer>andCommands. Control systems in the example run where they readButtonInput<KeyCode>andRes<Time>.