Manipulate non-send resources with Commands#12819
Closed
BD103 wants to merge 8 commits intobevyengine:mainfrom
Closed
Manipulate non-send resources with Commands#12819BD103 wants to merge 8 commits intobevyengine:mainfrom
Commands#12819BD103 wants to merge 8 commits intobevyengine:mainfrom
Conversation
Contributor
|
Tentatively marking this as controversial, as 9122 is supposed to be out of draft soon and seems to have broad support. @SkiFire13 asks on discord:
|
This makes the declaration order consistent with the surrounding methods of `Commands::remove_resource`. This is an opinionated change that I would be fine with reverting.
I incorrectly assumed that bevy was added as a dev-dependency. :)
Also remove the `is_in_fact_not_being_sent` test.
Member
Author
|
Closing this until #9122 is merged, where we can then reconsider it. |
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
ResourcesusingCommands, it is not possible to do the same for non-send resources (NonSend).bevy_command_non_send#12795 for full justification and additional discussion.bevy_command_non_send#12795.Sendresources out ofWorld#9122. I'd prefer that get merged instead of this one, but... uhhh...Solution
init_non_send_resource,insert_non_send_resource, andremove_non_send_resourcemethods forCommands.Commandsis accessible across threads,insert_non_send_resource's implementation takes a closure that creates the non-send resource on the main thread, instead of straight-up taking the value. This can be a bit confusing, so please check my documentation closely to make sure I explained it well!remove_resourcein 13e0f17, which is why the diff looks weird. I recommend looking at 314391c for the actual new content.Changelog
Commands.Migration Guide
This PR is not actually a breaking change, but I feel a migration guide is useful. Comment if you think I should remove it. :)
It is now possible to insert and remove non-send resources using
Commands. If you have any systems that take&mut Worldlike this:You can replace it with the following, which may yield performance improvements:
This also applies to the methods
init_non_send_resourceandremove_non_send_resource. Note thatCommands::insert_non_send_resourcetakes a closure, notMyNonSenddirectly. This closure's returned value will be inserted, after it is run on the main thread.Be warned that this may change the order of inserting your resource!
Commandsworks by delaying work untilapply_deferredis called. If you depend on a resource being inserted / removed within a schedule, usingCommandswill break your code.