Description
Discussed in #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.
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:
if !app.is_plugin_added::<DebugUiPlugin>() {
app.add_plugins(DebugUiPlugin);
}
if !app.is_plugin_added::<WireframePlugin>() {
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:
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.