bevyengine / bevyengine/bevy

Add and remove plugins at runtime

Open
#11,083 5 comments 7 reactions 0 assignees View on GitHub
A-App A-ECS C-Feature D-Complex
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 22h
Merged PRs (30d)
161

Description

## 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::(label: L)`, and it removes plugin with all its configurated systems, resources, states, etc.
And add resource `AppCommands` for change App with label. And resource `AppSettings` for get current settings.
Example:
``` rust
...
fn add_mods(mut app_cmd: ResMut, app_cfg: Res) {
// Check mods folder
if app_cfg.is_exist::(ModLabel("MOD_NAME")) {
app_cmd.remove_plugin::(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:
``` rust
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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.