-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Add BRP method to mutate a component #16940
base: main
Are you sure you want to change the base?
Conversation
@@ -48,6 +48,9 @@ pub const BRP_REPARENT_METHOD: &str = "bevy/reparent"; | |||
/// The method path for a `bevy/list` request. | |||
pub const BRP_LIST_METHOD: &str = "bevy/list"; | |||
|
|||
/// The method path for a `bevy/reparent` request. | |||
pub const BRP_MUTATE_COMPONENT_METHOD: &str = "bevy/mutate_component"; |
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.
I'm not sure what the convention is for multiple words in a method name is. Should the method be named differently? I'm trying to consider future methods for modifying other things like Resource's.
I had a few other ideas for methods:
bevy/modify/component
bevy/mutate/component
bevy/component_mut
this feels too Rusty in this context
20785c1
to
9e738a6
Compare
9e738a6
to
204e049
Compare
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.
This generally LGTM.
It's a shame that we don't have unit tests for BRP
I agree. I did look at writing tests for this, but I didn't see an existing way to do this. |
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.
It would be useful to link to the following docs in the crate level docs for this method to show how the path field should be structured.
https://docs.rs/bevy/latest/bevy/prelude/trait.GetPath.html#syntax
Your PR increases Bevy Minimum Supported Rust Version. Please update the |
Good point on that doc link. Added. |
Objective
Add a method to mutate components with BRP.
Currently the only way to modify a component on an entity with BRP is to insert a new one with the new values. This isn't ideal for several reasons, one reason being that the client has to know what all the fields are of the component and stay in sync with the server.
Solution
Add a new BRP method called
bevy/mutate_component
to mutate a single field in a component on an entity.Testing
Tested on a simple scene on all
Transform
,Name
, and a custom component.Showcase
Example JSON-RPC request to change the
Name
of an entity to "New name!"Or setting the X translation to 10.0 on a Transform:
Clip of my Emacs BRP package using this method:
output.mp4