Prerequisite plugins and resources / dependency handling: .require_plugin()
and .require_resource()
.
#14192
Labels
A-App
Bevy apps and plugins
C-Feature
A new feature, making something new possible
X-Contentious
There are nontrivial implications that should be thought through
What problem does this solve or what need does it fill?
Bevy does not currently provide an ergonomic way to handle prerequisite plugins / resources in the same fashion of similar initialisation / configuration concerns of apps.
Adding plugins and resources that may or may not already be added to the app requires condition checking outside of the usual chain of
app.add_plugin(...).insert_resource(...).
etc. that you would have inPlugin::build()
ormain()
.Often this is done for setting up prerequisites, such as plugins which rely on
egui
checking to make sureEguiPlugin
is added.In these cases, a bit of semantics is lost in the code, which may obfuscate the code-writer's intent. It also unnecessarily separates initialisation logic into multiple parts of your code.
For example, the following patterns are very common:
What solution would you like?
I propose
App::require_plugin::<T>(auto_init: bool) -> ?
andApp::require_resource::<T>(auto_init: bool) -> ?
. The?
type here could be, for example, aResult
for better error checking.These functions would perform the same sort of checking in the code above, but making the code more concise and better preserving semantics / intent.
Example:
Additionally,
.require_*
functions may be able to log that a panic was caused due to a dependency error, which may or may not happen when using the current method of manually checking - particularly if dependency checking is done many times throughout the code and the developer has forgotten to write sufficient logging logic.Issues with this solution
Default
constructor, altering the app initialisation if a resource/plugin is not present, etc.app.require_plugins::<(EguiPlugin, PlayerPlugin, ClientPlugin)>()
. Maybe another solution than the one proposed would allow similarly ergonomic code.Additional context
Many other languages and frameworks such as PHP, NodeJS, Lua, Elixir, etc. have implemented requirement handling for conditional initialisation of external code.
This too alleviates the need for manual checking, and makes the intent of the code more clear.
Additional additional context
If this gets accepted and the behaviour / implementation details are decided upon, I'd be more than happy to create a PR with my implementation :)
The text was updated successfully, but these errors were encountered: