make Plugin::build consume the plugin#1045
make Plugin::build consume the plugin#1045blunted2night wants to merge 4 commits intobevyengine:mainfrom
Plugin::build consume the plugin#1045Conversation
|
I think I'll hold off on merging this for a bit because I'm not quite sure I want plugins to be "one time use". Right now they serve as "re-usable arbitrary app initializers". We don't use that property today, but there may be a scenario where its desirable (ex: editors / dynamic plugins / multiple identical app instances / etc). It also sort of goes against the pattern of "configuring plugins via resources". Is the solution we came to in #1037 a suitable middle ground in the interim? app
.add_resource(AssetServer::new(CustomAssetIo, task_pool))
.add_plugins(DefaultPlugins) |
|
Yeah, this was just an idea that popped into my head. |
|
Cool cool. Yeah the approach in this pr might be the right call. I just want to think a bit about the implications first (which I can't do thoroughly right now). |
|
I'm going to close this for now as I don't see much of a reason to break things (and we might want Plugins to be reusable for certain scenarios). We can re-open this if/when the need arises. |
This patch makes the
buildmethod of thePlugintrait consume the plugin. This allows the plugin to transport non-clone-able configuration data into the build process of the plugin. Because this changes a core trait, it ends up touching a-lot, but in the vast majority of cases the change is just removing a&fromselfin thebuildmethod. It will break most users too, but the fix should in most if not all cases should just be removal of the&fromselfin thebuildmethod. It also changes the signature of the dynamically loaded plugin factory function slightly.The relevant changes, those not just fixing the signature, are in "crates/bevy_app/src/plugin.rs" and "crates/bevy_app/src/plugin_group.rs".
There are two instances in the existing code base that utilized the plugin to transport data into the build process, the
PrintDiagnosticsPluginand the examplePrintMessagePluginwhich no longer needed to clone the data and can instead just transfer ownership.My use case for this a precursor for one last alternate approach to overriding the
AssetIoinstance used in theAssetServer. With this in place, it would be possible to implement overriding theAssetIolike so:This patch is necessary for this approach to work since
AssetIodoes not, and should not, in my opinion, implementClone.I don't know what future plans may be in store for the plugin system, so this might be taking things in the wrong direction.