Tracked one-shot systems#24165
Open
ItsDoot wants to merge 4 commits intobevyengine:mainfrom
Open
Conversation
chescock
approved these changes
May 7, 2026
Contributor
chescock
left a comment
There was a problem hiding this comment.
Looks good! I left some comments, but they're just style nits.
| I: SystemInput + 'static, | ||
| O: 'static, | ||
| { | ||
| let id = id.into(); |
Contributor
There was a problem hiding this comment.
Do we need to worry about this monomorphizing two versions of this function?
Contributor
Author
There was a problem hiding this comment.
Maybe! Would be good to check how much of a difference the codegen is
Co-authored-by: Chris Russell <8494645+chescock@users.noreply.github.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Objective
#24087 introduces scene templating for
SystemIds, however it can result in a memory leak if a scene is re-constructed multiple times:#24087 (comment)
#24087 (comment)
Essentially, we need a way to connect the lifetime of the registered system to the lifetime of the scene.
Solution
This is a purely additive / opt-in / backwards-compatible version of #24114
Introducing:
SystemHandlesSimilar to
bevy_asset::Handles,SystemHandle's customDropimplementation enqueues the registered system entity into a concurrent queue. The systemdespawn_unused_registered_systemspulls from the other end of this queue and despawns the registered system entities.World::register_tracked_systemandWorld::register_tracked_boxed_systemare the only functions that returnSystemHandles.Testing
despawn_unused_registered_systemsdoes its jobdespawn_unused_registered_systemsFuture work
SystemIdscene templating #24087 will use this PR as a base