Implementing PluginGroup with multiple closure causes DuplicatePlugin error
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 16h
- Merged PRs (30d)
- 171
Description
## Bevy version and features
bevy = "0.18.1"
## What you did
Im trying to impl a PluginGroup by multiple closures.
```rust
use bevy::{app::{App, PluginGroup, PluginGroupBuilder, Startup, Update}};
pub fn a_sys(){}
pub fn b_sys(){}
pub struct APluginGroup;
impl PluginGroup for APluginGroup {
fn build(self) -> PluginGroupBuilder {
PluginGroupBuilder::start::()
.add(|app:&mut App|{app.add_systems(Startup, a_sys);})
.add(|app:&mut App|{app.add_systems(Update, b_sys);})
// .add(add_b_sys)
}
}
pub fn add_b_sys(app:&mut App){
app.add_systems(Update, b_sys);
}
#[test]
pub fn test(){
let mut app=App::new();
app.add_plugins(APluginGroup);
}
```
## What went wrong
thread 'examples::bug1::test' (1264) panicked at blabla\src\examples\bug1.rs:25:9:
Error adding plugin ::build::{{closure}} in group blabla::examples::bug1::APluginGroup: plugin was already added in application
notes that both closures in build have the same name "{{closure}}", which is checked at `bevy_app::app::App::add_boxed_plugin`
This problem can be easily avoided, but the bug is weird and needs at least some reminder.
Contributor guide
Research direction
Start with App::add_boxed_plugin and the PluginGroupBuilder implementation referenced in the report. Reproduce the test with two closure plugins and compare it with the named add_b_sys function. Determine how plugin identity is assigned to closures, then verify the behavior with a regression test covering multiple closures in one PluginGroup.
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
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100