bevy
bevy copied to clipboard
Add and remove plugins at runtime
What problem does this solve or what need does it fill?
I want to add mods at runtime so I don't have to reload the game to add a mod. Replacing system for mod can change game logic.
What solution would you like?
Plugins
Add Plugin parameter ModPlugin.with_label(ModLabel("ModName"))
or with_label(ModPlugin, ModLabel("ModName"))
;
If there is the same plugin with the same label, then panic.
Label varies by ParticalEq
.
Add App function: remove_plugin::<T: PluginType, L: PluginLabel>(label: L)
, and it removes plugin with all its configurated systems, resources, states, etc.
And add resource AppCommands<Label>
for change App with label. And resource AppSettings
for get current settings.
Example:
...
fn add_mods(mut app_cmd: ResMut<AppCommands>, app_cfg: Res<AppSettings>) {
// Check mods folder
if app_cfg.is_exist::<ModPlugin>(ModLabel("MOD_NAME")) {
app_cmd.remove_plugin::<ModPlugin>(ModLabel("MOD_NAME"));
}
app_cmd.add_plugins(ModPlugin.with_label(ModLabel("MOD_NAME"));
}
...
App commands runs after all system.
System replace
Make passage to get SystemId and replacing by SystemId. For example:
let mut schelude = ...// getting schelude
let sys_id = schelude.get_system_ids(my_system).get(0).unwrap();
schelude.replace_system(sys_id, my_another_system);
What alternative(s) have you considered?
Plugins
Create your own plugin system for the runtime, but it will be limited (for example, no SubApp).
System replace
Make run_if
condition for disable it.
This is an extension of #279, which does this for systems. It's closely related to #2160, which proposes tools to work with plugins as a meaningful unit of organization, rather than just a trivial mutating function on App
.
@alice-i-cecile How i can help with #2160 and #279?
Maybe this should remain open if it isn't covered directly by the other mentioned issues? I'm just interested in these types of features so feel free to disregard this if its inappropriate.
I am also interested in this