Skip to content
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

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

purplg
Copy link
Contributor

@purplg purplg commented Dec 23, 2024

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 and Name fields.
  • Need to do more testing on other component types.

Showcase

Example JSON-RPC request to change the Name of an entity to "New name!"

{
    "jsonrpc": "2.0",
    "id": 0,
    "method": "bevy/mutate_component",
    "params": {
        "entity": 4294967308,
        "component": "bevy_ecs::name::Name",
        "path": ".name",
        "value": "New name!"
    }
}

@@ -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";
Copy link
Contributor Author

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

pub fn process_remote_mutate_component_request(
In(params): In<Option<Value>>,
world: &mut World,
) -> BrpResult {
Copy link
Contributor Author

@purplg purplg Dec 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like the method handler could probably be done better or maybe in less steps. Any pointers here would be appreciated.

@purplg purplg changed the title Add mutate_component BRP method Add BRP method to mutate a component Dec 23, 2024
@alice-i-cecile alice-i-cecile added C-Feature A new feature, making something new possible A-Dev-Tools Tools used to debug Bevy applications. S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Dec 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Dev-Tools Tools used to debug Bevy applications. C-Feature A new feature, making something new possible S-Needs-Review Needs reviewer attention (from anyone!) to move forward
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants