pyri_state is a bevy_state alternative offering flexible change detection & scheduling.
https://github.com/benfrankel/pyri_state by @modest imp
53 messages · Page 1 of 1 (latest)
pyri_state is a bevy_state alternative offering flexible change detection & scheduling.
https://github.com/benfrankel/pyri_state by @modest imp
it's been a while so let me double-check.. :p
yes there are no commands currently for state stack operations, it seems like it would be possible to add them, and probably would be desirable
I'll put up a PR if nobody gets to it first
let me know if you need any help
I'm curious what exactly the bevy_state feature does. Do I only need that enabled if I'm going to try and use both bevy_state and pyri_state?
Looks like it adds the bevy state plugin and adds some machinery to register pyri states with it? Like, it derives pyri::State and bevy_state::States?
The default experience seems to be: I cargo add bevy, cargo add pyri_state, then add (DefaultPlugins, StatePlugin), and then I get a crash on startup from Bevy's state plugin being added twice
@modest imp This prints nothing:
use bevy::prelude::*;
use pyri_state::prelude::*;
fn main() {
App::new()
.add_plugins((DefaultPlugins, StatePlugin)) // Adding the plugin
.insert_state(NextStateStack::with_base(Menu::Main)) // Initializing the state
.add_systems(Update, Menu::ANY.on_update(|| println!("Hello????????"))) // Check if we're in *any* state
.run(); // nothing prints
}
#[derive(State, Clone, PartialEq, Eq, Debug)]
#[state(next(NextStateStack<Self>))]
enum Menu {
Main,
}
Also I'm having trouble with the examples in the repo, I can't tell if they're not doing anything visible or if I don't know what they're supposed to be doing.
so currently the examples are mostly just examples of what the code looks like / sanity checks that the API compiles
some of the examples do include input / logging though so you can see the state changes in the logs
none of the examples include visuals atm although it would be nice if they did
like just a different bg color per state or w/e
that adds a compatibility layer between pyri_state's states and bevy_state's states
which you need if you're e.g. using an ecosystem crate that expects bevy_state states to function
like bevy_asset_loader
Should this print anything?
at a first glance i believe it should
hmmmmmm
maybe the .insert_state line is the issue
time to debug 🫡
yeah you need to disable the bevy_state feature on bevy
which means disabling default features and re-enabling everything except bevy_state
which is a little annoying but at least it works 😄
you can then depend on bevy_state directly if you want. it won't be pulled into the bevy prelude or automatically add its plugin, so there's no compatibility issue with doing that
@modest imp what are the chances that pyri_state “unwinds” states in the “correct” order?
For example if I have a substate and I have a system listening to its OnExit (equivalent thereof), could I rely on that OnExit being called before the parent state’s OnExit?
Use case is that in my substate OnExit I am cleaning up some resources, but the parent’s OnExit also cleans up resources. The substate OnExit needs those resources first though, so I need strict ordering here and I don’t see a way to get it from bevy_state.
in pyri_state, substates and computed states are replaced with the concept of "dependent states"
which is under the hood quite literally .after or .before on some system sets
meaning you can specify that one state type's transitions should always run before another state type's transitions
Yeah nice. So: yes is the answer 🙂
yeah :)
although in bevy_state there is also ordering between parent and sub/computed states
specifically, it's like nested parens
"on enter" for the parent state, then "on enter" for the child state, then "on exit" for the child state, then "on exit" for the parent state
Previously when I’ve looked at the repo, the first question that pops in my head is: but what about bevy_asset_loader. So you may consider adding a note or FAQ to the readme if you feel like it. Pretty sure using pyri means you can’t use bevy_asset_loader without your work, but could be worth being explicit 🤷
good point. you actually can use them together but it's a little extra work
pyri_state has a feature where it can create a synced bevy_state state type for your states
which provides a compatibility layer
but for bevy_asset_loader specifically, it depends on bevy directly with the bevy_state feature enabled, which causes issues because that injects conflicting names into the bevy prelude
the workaround for that is to patch to my PR for now: https://github.com/NiklasEi/bevy_asset_loader/pull/233
i should probably mention this somewhere
here's an example for this: https://github.com/benfrankel/pyri_state/blob/main/examples/bevy_state.rs
Yep aware of your PR. I’m a fan for other reasons but that’s OT haha
ahh i misread your message, got it
Hmm I’ll come back with this. I thought my substate was using the resource that the parent also cleans up but maybe it’s got a different parent (I’ve been refactoring my states heavily because I now preload the next screen so my state design is getting complicated and using lots of computed states). That’s to say maybe I’d have similar issues if I used pyri
That’s a smart idea. I guess it would be neat if BAL was more agnostic and could even accept a pyri state feature.
yeah, swapping out core bevy plugins is a tough problem. either the replacement has to be compatible with the rest of the ecosystem or vice versa. alternatively there could be a common interface with traits etc. like rand_core, but that's probably overengineered