Profile Picture

Spencer B.

President/Lead Developer at the Quaternion Institute. CS student, programmer, and guitarist.

feed | tips | contact

How to Disable Audio in the Bevy Game Engine

Calendar icon January 22, 2021

Clock icon 2 min read

Folder icon #bevy #gamedev #rust #audio #music #linux in tech

Why Disable Audio?

You probably don’t want to disable audio. Unless, that is, your audio setup is giving you issues and impeding development.

In my case, I get an error message from the Rodio crate that Bevy uses that looks like this:

ALSA lib pcm_dmix.c:1108:(snd_pcm_dmix_open) unable to open slave
thread 'main' panicked at 'The device doesn't support any format!?: DeviceNotAvailable', /home/spencer/code/project/audiofile.rs:10:10

In my case, it seems that Rodio is trying to connect to ALSA instead of Pulseaudio. This is a problem because ALSA only supports one output, hence the need for Pulseaudio (which is probably using that single output and acting like a virtual splitter jack). This specific issue is tracked on GitHub here.

Cargo Features

Bevy comes with a Cargo feature that enables audio by default. There is a full list of features in the docs and in Cargo.toml.

Anyways, go to your project’s Cargo.toml, remove the bevy line from under [dependencies] and add the following:

[dependencies.bevy]
version = "0.4"
default-features = false
features = ["bevy_gltf", "bevy_winit", "bevy_wgpu", "render", "bevy_dynamic_plugin", "png", "hdr", "x11"]

This does three things:

  1. Replaces the bevy line we just removed
  2. Tells Cargo that we don’t want Bevy’s default features
  3. Tells Cargo that we want every default feature except bevy_audio and mp3

Hope this helped.

Comments