Skip to content
This repository was archived by the owner on May 27, 2025. It is now read-only.

Add RemoveComponents example to demo 'infinite' system bug - #23

Open
mgi388 wants to merge 1 commit into
SolarLiner:mainfrom
mgi388:remove-components-infinite-bug
Open

Add RemoveComponents example to demo 'infinite' system bug#23
mgi388 wants to merge 1 commit into
SolarLiner:mainfrom
mgi388:remove-components-infinite-bug

Conversation

@mgi388

@mgi388 mgi388 commented Jun 22, 2024

Copy link
Copy Markdown
Contributor

Description

When you use AudioFileEndBehavior::RemoveComponents, the system that actually handles the removal of the components loops infinitely. To repro, run the example and look in the terminal at the 'infinite' log entry.

The removal code removes AudioFileBundle but the query that the system uses queries for AudioHandle<AudioFileHandle>, and that's not a part of AudioFileBundle therefore the query always matches.

I think the logic error is that the removal code assumes that removing AudioFileBundle is enough, because that's the minimal set of components callers need to add to an entity to make it play audio audio. However, bevy-kira-components can internally add more components. In this case it adds AudioHandle:

commands.entity(entity).insert(AudioHandle(handle));

Therefore I think one solution is that the removal code just needs to be aware of all of the extra components it may add and one fix looks like this:

commands
  .entity(entity)
  .remove::<AudioFileBundle>()
  .remove::<AudioHandle<AudioFileHandle>>();

This seems to be in line with the original goal of RemoveComponents which is to make the entity look how it looked before the caller added AudioFileBundle i.e. the caller is really asking bevy-kira-components "please: remove all the audio components".

P.S. It was easier to just push the repro example as a PR than create a new issue and I also thought that if it was desired we could keep this example, and once the bug is fixed we can enable the on_audio_file_removed to demonstrate how you can change sounds once the previous sound has finished playing.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant