-
|
Hi, I recently read this blog post: I found the approach really interesting and wanted to try it out myself. However, it looks like the Flecs API has changed since the article was written. I came across the same example using union traits here: But there's a warning indicating that support for the Union trait will be deprecated and replaced by exclusive DontFragment relationships. So, what's the recommended way to implement this kind of state machine in Flecs as of 2025? I'm using the Rust bindings, and my entities can be in one of three states: What would be the best way to model this, allowing transitions like: Thanks in advance for your help! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
Use exclusive relationships with |
Beta Was this translation helpful? Give feedback.
Use exclusive relationships with
DontFragmentandExclusivetraits (replaces deprecated Union). Create a state relationship:let state = world.entity().add_trait::<flecs::DontFragment>().add_trait::<flecs::Exclusive>(). Define state entities, then add states viaentity.add_id((state, current_state)). The Exclusive trait automatically removes the previous state when you add a new one, enabling clean state transitions. See docs/ComponentTraits.md for details.