Struggling with dynamic library plugins #8390
-
I'm making a game in which I'd like to be able to hotload mods. As the post name implies, I'm planning to do this with Bevy plugins, which will then do their own things like registering new items and whatnot. I managed to create a After a lot of digging, I finally came across bevy_dynamic_plugin - which is exactly what I need... But I couldn't find any documentation for it besides a couple footnotes on docs.rs. Anyway, here's my non-working code for the library that I scraped together: #![crate_type = "dylib"]
use bevy::prelude::*;
#[no_mangle]
pub fn _bevy_create_plugin () -> TestPlugin {
println!("[dylib] This is called");
return TestPlugin; // This compiles but I'm not sure it's right
}
pub struct TestPlugin;
impl Plugin for TestPlugin {
fn build (&self, app: &mut App) {
println!("[dylib] This isn't called");
app.add_startup_system(test_plugin);
}
}
pub fn test_plugin () {
println!("Test plugin running");
} And the Bevy client loading said library: use bevy::prelude::*;
use bevy_dynamic_plugin::DynamicPluginExt;
use libloading;
fn main () {
let mut app = App::new();
unsafe {
println!("[main] Loading dynamic plugin");
app.load_plugin("./libtestmodule.so");
}
println!("Running");
app.run();
} And the only things printed are:
Setting Oh, and as a sidenote, let's say I have a couple components defined in the main app code; how would I go about querying or accessing them from a dynamic library? Should I put |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 5 replies
-
The documentation for That said, personally I would avoid hotreloading dynamic libraries for now. There are a ton of things that can go wrong when loading a dynamic library in Rust (especially one which uses non- |
Beta Was this translation helpful? Give feedback.
-
Thanks for the tip, but I think dynamic libraries are my only choice, even if they're unstable - I don't see another way to natively support modding... Except using embedded Lua to make plugins, but that's an absolute last resort. I managed to have
So, I tried to Thanks for your help! |
Beta Was this translation helpful? Give feedback.
-
Just curious; would moving all struct definitions into a separate library that gets shared between the game and the mod resolve the |
Beta Was this translation helpful? Give feedback.
And are the game and the mod in the same cargo project/workspace? If not, do they share the same version and features for bevy (but it would be better if that was true for all the other dependencies too)
Probably, but I'm not sure how you would do that,…