Skip to content

Implement exclusive app hooks#20975

Open
radiantgurl wants to merge 3 commits intobevyengine:mainfrom
radiantgurl:exclusive_app_hooks
Open

Implement exclusive app hooks#20975
radiantgurl wants to merge 3 commits intobevyengine:mainfrom
radiantgurl:exclusive_app_hooks

Conversation

@radiantgurl
Copy link

@radiantgurl radiantgurl commented Sep 11, 2025

This PR depends on another PR #21239

Objective

  • Modifying / accessing SubApps at runtime
  • Opening a way for dynamic plugin integration
  • Mod loading

Solution

  • Exclusive app access hooks

Testing

Ran cargo check
Tested to ensure no runtime errors.


Showcase

cargo run --example exclusive_hook

@radiantgurl radiantgurl force-pushed the exclusive_app_hooks branch 2 times, most recently from 5e37c0f to f777430 Compare September 11, 2025 23:26
@janhohenheim janhohenheim added A-App Bevy apps and plugins S-Needs-Review Needs reviewer attention (from anyone!) to move forward X-Contentious There are nontrivial implications that should be thought through D-Straightforward Simple bug fixes and API improvements, docs, test and examples labels Sep 11, 2025
Copy link
Contributor

@ChristopherBiscardi ChristopherBiscardi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code seems fine generally. The std::mem::take and loop of the hashmap happens every update regardless of if there are hooks defined or not.

I'm not aware of why this is x-contentious though, so this is just a review of the code as implemented, not a review of the exclusive hook feature.

I'd love to see an example for this in examples/

@alice-i-cecile
Copy link
Member

alice-i-cecile commented Sep 19, 2025

I've marked this as Contentious because I don't immediately understand the use case, and am not convinced that this is the best way to accomplish these goals.

Better documentation may be the right fix, but this PR also needs end to end tests verifying that this works as intended.

@radiantgurl radiantgurl force-pushed the exclusive_app_hooks branch 2 times, most recently from 1e9704a to e482770 Compare September 19, 2025 19:56
@alice-i-cecile alice-i-cecile added this to the 0.18 milestone Sep 20, 2025
@radiantgurl
Copy link
Author

radiantgurl commented Sep 20, 2025

Any meetings or places to discuss it?

I'm currently trying to find out why im getting completely unrelated errors to this code even though i've already tested it.

This code aims to allow better modding support, maybe we can discuss with core team to implement a DynamicPlugin system to better utilize this and allow for dynamic plugin building?

My vision of bevy is a game engine with lots of redundancy and modularity, while allowing to dynamically modify the game engine at runtime without a restart being required, unlike winit's event handler. This would allow us to have a lot more modding support, maybe even make it built into bevy directly.

@radiantgurl
Copy link
Author

Also i have no idea how to fix the CI issues considering its not related to my changes.

@james7132
Copy link
Member

james7132 commented Sep 20, 2025

I'm currently trying to find out why im getting completely unrelated errors to this code even though i've already tested it.

CI was broken with the release of Rust 1.90. Just updated your branch to incorporate the fix..

My vision of bevy is a game engine with lots of redundancy and modularity, while allowing to dynamically modify the game engine at runtime without a restart being required, unlike winit's event handler. This would allow us to have a lot more modding support, maybe even make it built into bevy directly.

Is this not possible with our existing schedule APIs? Schedules already live in the World, and can be mutated at runtime from within an exclusive system. The only thing it's missing is the ability to change out the top level app runner while it is currently running. At the same time, I don't think this is particularly ergonomic right now, butthis does seem like an easy path to crashes/violated logical invariants, and thus shouldn't be explicitly encouraged unless there is a very compelling use case for it.

@radiantgurl
Copy link
Author

The only thing it's missing is the ability to change out the top level app runner while it is currently running.

Not only that, it also doesnt allow you to access other subapps which is a shame. This not only allows access to other subapps but also allows modifying and creating new ones, giving further modding possibilities.

this does seem like an easy path to crashes/violated logical invariants

That issue was resolved by making app hooks unaccessible during app runtime, resulting in no violation. What is being done fully respects rust's borrow semantics, with no extra unsafe usage, meaning there should be no issues caused by this.

The only thing i have to add is to turn the hook hashmap into an option and make it panic when you attempt to access it during runtime.

@radiantgurl radiantgurl force-pushed the exclusive_app_hooks branch 3 times, most recently from f6ca681 to 88f72b6 Compare September 27, 2025 12:01
@radiantgurl
Copy link
Author

Added a new example cargo run --example exclusive_hook

radiantgurl and others added 2 commits September 27, 2025 15:24
Co-authored-by: Chris Biscardi <chris@christopherbiscardi.com>
@radiantgurl radiantgurl force-pushed the exclusive_app_hooks branch 2 times, most recently from 05737af to 9ed4a43 Compare September 28, 2025 08:26
@alice-i-cecile alice-i-cecile removed this from the 0.18 milestone Dec 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-App Bevy apps and plugins D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review Needs reviewer attention (from anyone!) to move forward X-Contentious There are nontrivial implications that should be thought through

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants