-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hot reloading of Rust functions for mods and faster development #1095
Comments
I have one comment
If you've looked at the code at all, even for a moment, you risk a "re-implementation" being deemed "derivative work" and thus also having to be licensed under the GPL. The other option is feasible, but you'd have to get permission from all three contributors to do that. This isn't impossible though so its worth trying if this is something important to bevy. |
This crate is also really new, only on it's first published version. Development will be active again shortly, so if the bevy team needs additional features or fixes that's an option. One comments on OP's message:
This currently is supported in hotpatch, but is |
This blog post looks to be a useful log of exploring some of the implementation details of this sort of work. It's very detailed and stream-of-thought though, so it's probably more useful once we actually start building. |
That's my initial thought: that with dynamically linked game code that actually arleady have the build times might not even get that bad for small-medium games. But also it seems like the concept of hot-reloaded systems may be rather simple to accomplish if you only patched them at the end of every frame. ( I'm no expert, though. :) ) |
I would advocate for using WASM instead of hotloading DLLs. In addition to allowing hotloading during development, WASM modules run in a sandbox environment and can only interact with the host in a predefined way. Thus they can be trusted not to execute malicious code. This opens up the possibility for user generated code extensions for Bevy games and also the Bevy editor, (once we have one). Microsoft did this in the latest Flight Simulator to enable safe community extensions. |
The disadvantage of using wasm is that it requires writing glue code for every type that needs to be passed between the wasm plugin and the main game executable. Also sometimes this sandboxing may not be desired. For example when requiring direct access to os libraries. Finally it requires shipping a wasm compiler, which may not be desired for code size reasons or because the target os doesn't allow jitting. cough iOS cough Supporting both WASM and dynamic libraries would be an option though I think. Allowing to choose the most appropriate tool for the job. |
An interesting article (and associated crate) exploring this for use with Bevy: https://robert.kra.hn/posts/hot-reloading-rust/ Some very serious limitations, but may still be useful if you build a workflow around it. |
I believe this can now be somewhat resolved with the WASM Component Model, right? |
The wasm component model doesn't allow direct access to rust types. You still need glue code, just a bit less complex glue code. |
What problem does this solve or what need does it fill?
Describe the solution would you like?
Load in new function definitions from shared object files, allowing changes to game logic while it is running.
The basic behaviour outlined in the hotpatch crate works smoothly for mods, but for development, it would be ideal to have it automatically detect changes to the saved source files (when an appropriate flag is set). This behaviour is very similar to the existing hot reloading of assets.
A few caveats:
#[patchable]
would get old quickly: we'd need to find some refactoring to replace this requirement with a global feature flag.Describe the alternative(s) you've considered?
Mods could work by purely adding code, integrating a scripting language, or incorporating this sort of functionality in an external library. The potential benefits to development speed push me towards offering this as a core bit of functionality if possible.
Development / testing loops might be fast enough with dynamic linking to improve compile times + high quality state saving and loading. Without testing on large code bases, it's unclear what sort of iteration speeds this might offer.
Additional context
The new hotpatch crate, discussed on reddit here was the inspiration for this feature request, and seems to have some nice technical capabilities. As is, we can't incorporate it due to the GPL license, but we could create an MIT re-implementation or work with its author to change the license.
The text was updated successfully, but these errors were encountered: