-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Refactor state scoped events to match entities. #19435
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
Merged
alice-i-cecile
merged 16 commits into
bevyengine:main
from
AlephCubed:state-scoped-standardization
May 31, 2025
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
b8c6040
Loosen `add_state_scoped_event` trait bound.
AlephCubed 45fbc70
Rename `StateScopedEvents` to `ClearEventsOnExitState`.
AlephCubed b7118e5
Changed to `clear_event_on_exit_state`, which no longer adds the event.
AlephCubed 7b2b949
Reverted `StateScopedEvents` resource rename.
AlephCubed 1435120
Fixed bugs and added tests.
AlephCubed fafb6f9
Rename migration guide file.
AlephCubed c761b7e
Update migration guide.
AlephCubed b92b361
Updated documentation.
AlephCubed b5af538
Merge remote-tracking branch 'upstream/main' into state-scoped-standa…
AlephCubed a56267e
Fix type in migration guide.
AlephCubed ab06f08
Add pr number to migration guide.
AlephCubed 4883353
Run cargo fmt.
AlephCubed 60e887f
Merge remote-tracking branch 'upstream/main' into state-scoped-standa…
AlephCubed f71b07d
Method now adds the event, matching previous behaviour.
AlephCubed 3ca31b7
Updated tests to include normal event.
AlephCubed 0ca53bf
Revert back to `clear_events_on_exit_state`.
AlephCubed File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- | ||
title: Renamed state scoped entities and events | ||
pull_requests: [18818, 19435] | ||
--- | ||
|
||
Previously, Bevy provided the `StateScoped` component and `add_state_scoped_event` method | ||
as a way to remove entities/events when **exiting** a state. | ||
|
||
However, it can also be useful to have the opposite behavior, | ||
where entities/events are removed when **entering** a state. | ||
This is now possible with the new `DespawnOnEnterState` component and `clear_events_on_enter_state` method. | ||
|
||
To support this addition, the previous method and component have been renamed. | ||
Also, `clear_event_on_exit_state` no longer adds the event automatically, so you must call `App::add_event` manually. | ||
|
||
| Before | After | | ||
|-------------------------------|--------------------------------------------| | ||
| `StateScoped` | `DespawnOnExitState` | | ||
| `clear_state_scoped_entities` | `despawn_entities_on_exit_state` | | ||
| `add_state_scoped_event` | `add_event` + `clear_events_on_exit_state` | |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not for this pr, but it's a little strange that a clear on transition event might not be cleared if the state is immediately changed again quickly.