-
-
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
BRP resource methods #17423
base: main
Are you sure you want to change the base?
BRP resource methods #17423
Conversation
This looks good to me. Excited to see these new methods implemented. Do we want to consider renaming the methods to be a little more hierarchical in the future or maybe some other scheme? For example:
I feel like they may get a little unwieldy over time as more and more methods are added. |
This is a very good idea. I'll change them when I have time :) (I guess there's also the question of which other methods, if any, should get moved to the |
Objective
So far, built-in BRP methods allow users to interact with entities' components, but global resources have remained beyond its reach. The goal of this PR is to take the first steps in rectifying this shortfall.
Solution
Added five new default methods to BRP:
bevy/get_resource
: Extracts the value of a given resource from the world.bevy/insert_resource
: Serializes an input value to a given resource type and inserts it into the world.bevy/remove_resource
: Removes the given resource from the world.bevy/mutate_resource
: Replaces the value of a field in a given resource with the result of serializing a given input value.bevy/list_resources
: Lists all resources in the type registry with an availableReflectResource
.Testing
Added a test resource to the
server
example scene that you can use to mess around with the new BRP methods.Showcase
Resources can now be retrieved and manipulated remotely using a handful of new BRP methods. For example, a resource that looks like this:
can be manipulated remotely as follows.
Retrieving the value of the resource:
Inserting a resource value into the world:
Removing the resource from the world:
Mutating a field of the resource specified by a path:
Listing all manipulable resources in the type registry: