Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mgi388
Copy link
Contributor

@mgi388 mgi388 commented Jun 22, 2024

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 join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

None yet

1 participant