bevyengine / bevyengine/bevy

`AudioSink` is not updated when audio source component is replaced

Open
#11,862 1 comment 2 reactions 0 assignees View on GitHub
A-Audio C-Bug
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 16h
Merged PRs (30d)
171

Description

## Bevy version

```toml
bevy = { version = "0.12.1"}
```

## What you did

Here is the code I have problems with:

https://gist.github.com/rambip/43a977c833edef252ae7e3d17203287a

To resume, I:
- create a custom audio source like in the "decodable" official example
- add it as a component to start playing it
- change the component with another audio source
- set a control on the space bar to play and pause the sink associated with the entity

## What went wrong

I expected this code to play and pause the lowest-pitch sample.
But it plays nothing.

I tried a few other experiments (like rechanging the audio-source to the original one, and then it worked)

I found a way to do what I intended: forcing the sink to be destroyed when I change the source.

## Discussion

I don't think it is the expected behaviour, or at least I think it is very confusing. My take is that the Sink should be removed when you insert an audio-source on an entity that already has one.

The user should know how the sinks are created and modified when the sources are spawned. Otherwise you quickly run into strange behaviours that are hard to debug.

Contributor guide

Open the contributing guide

Research direction

Start with the reproduction in the linked gist and compare it with Bevy's official "decodable" audio example. Trace how an AudioSink is associated with an entity when its audio-source component is replaced, then check the existing audio behavior around that replacement. Done means the provided reproduction plays and pauses the replacement source as expected, with tests covering the behavior if the relevant test location is found.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
game-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.