Skills

Bevy Audio Systems

Bevy ECS skill for audio playback.

Install

npx skills add thedivergentai/Game-Dev-Agentic-Skills --skill bevy-audio-systems -g -a claude-code -y
Category
Media
Updated
19d ago
License
LGPL-3.0
Context cost
Mediumabout 1,973 tokens
Runs scripts
No, instructions only

What it does

Bevy ECS skill for audio playback. Keywords: Bevy, AudioPlayer, AudioSink, PlaybackSettings, AssetServer.

Bevy audio systems

When to use

Load this when a clip should start, loop, pause, or change volume. bevy::audio in Bevy 0.20 and the audio_control example are the sources.

ECS shape

  • Play: spawn AudioPlayer::new(asset_server.load(...)). AudioPlayer<Source> holds Handle<Source> where Source: Asset + Decodable. If the asset is not ready, playback starts when it is. AudioPlayer requires PlaybackSettings.
  • Settings: PlaybackSettings configures the start. PlaybackSettings::LOOP and .with_spatial(true) appear in the spatial examples. Changes to PlaybackSettings do not affect audio that is already playing. PlaybackMode is Once, Loop, Despawn, or Remove.
  • Control: when playback begins, Bevy inserts AudioSink. The control example queries AudioSink and calls pause, toggle_mute, set_volume, set_speed, and position. SpatialAudioSink is the spatial counterpart named on the playback page.
  • Replay: after a non-looping sound finishes and the sink is drained, that AudioPlayer cannot be reused. Remove the audio components and add them again.
  • Schedule: spawn on Startup or from a system that has Res<AssetServer> and Commands. Control systems in the example run where they read ButtonInput<KeyCode> and Res<Time>.

Playback pieces

NeedBevy idiom
Start a fileAudioPlayer::new plus AssetServer::load
LoopPlaybackSettings::LOOP
Pause, mute, or volume while playingAudioSink methods on the same entity
One-shot that should leave the worldPlaybackMode::Despawn or Remove
Positional emitterPlaybackSettings with with_spatial(true) and SpatialAudioSink

Examples

[dependencies]
bevy = "0.20"

AudioPlayer starts when the handle is ready. PlaybackSettings applies only at that start. AudioSink is inserted once playback begins and is the live control.

use bevy::audio::{AudioSinkPlayback, Volume};
Read the whole SKILL.md on GitHub

More in Media