Add `try_add_plugins` for apps a la `try_insert` for entities
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 22h
- Merged PRs (30d)
- 161
Description
### Discussed in https://github.com/bevyengine/bevy/discussions/15802
Originally posted by **mgi388** October 10, 2024
We have `try_insert` for entities. Doc:
> Unlike [`Self::insert`], this will not panic if the associated entity does not exist.
```rust
x.try_insert(CombatBundle {
health: Health(100),
strength: Strength(40),
});
```
Could we have `try_add_plugins` for apps? Doc:
> Unlike [`Self::add_plugins`], this will not panic if any of the plugins are already added.
Instead of this:
```rust
if !app.is_plugin_added::() {
app.add_plugins(DebugUiPlugin);
}
if !app.is_plugin_added::() {
app.add_plugins(WireframePlugin);
}
```
Which gates against panics like this:
```
Error adding plugin bevy_pbr::wireframe::WireframePlugin: : plugin was already added in application
```
The new function would let us do this:
```rust
app.try_add_plugins((WireframePlugin, DebugUiPlugin));
```
Motivation: I have 10s of lines of code of plugins being added only if they aren't already added and it would save lines but also possible bugs (when you copy paste and forget to change both instances of the plugin name).
I know there are lots of floating ideas around plugin dependencies / requirements, etc. but I wonder if this is a small enough API additional that it doesn't hurt in the long run even if/when a new API arrives.
Contributor guide
Assessment
This issue has not been assessed yet.