Allow registering of resources via ReflectResource / ReflectComponent#15496
Merged
alice-i-cecile merged 5 commits intobevyengine:mainfrom Sep 28, 2024
Merged
Allow registering of resources via ReflectResource / ReflectComponent#15496alice-i-cecile merged 5 commits intobevyengine:mainfrom
alice-i-cecile merged 5 commits intobevyengine:mainfrom
Conversation
Member
MichalGniadek
approved these changes
Sep 28, 2024
Contributor
MichalGniadek
left a comment
There was a problem hiding this comment.
LGTM
There is now a difference between behavior. now, it's possible to have a Resource registered in the world without any values.
I think this should be equivalent to initing a resource and immediately removing it.
alice-i-cecile
approved these changes
Sep 28, 2024
robtfm
pushed a commit
to robtfm/bevy
that referenced
this pull request
Oct 4, 2024
…bevyengine#15496) # Objective - Resolves bevyengine#15453 ## Solution - Added new `World::resource_id` and `World::register_resource` methods to support this feature - Added new `ReflectResource::register_resource` method, and new pointer to this new function - Added new `ReflectComponent::register_component` ## Testing - Tested this locally, but couldn't test the entire crate locally, just this new feature, expect that CI will do the rest of the work. --- ## Showcase ```rs #[derive(Component, Reflect)] #[reflect(Component)] struct MyComp; let mut world = World::new(); let mut registry = TypeRegistration::of::<MyComp>(); registry.insert::<ReflectComponent>(FromType::<MyComp>::from_type()); let data = registry.data::<ReflectComponent>().unwrap(); // Its now possible to register the Component in the world this way let component_id = data.register_component(&mut world); // They will be the same assert_eq!(component_id, world.component_id::<MyComp>().unwrap()); ``` ```rs #[derive(Resource, Reflect)] #[reflect(Resource)] struct MyResource; let mut world = World::new(); let mut registry = TypeRegistration::of::<MyResource>(); registry.insert::<ReflectResource>(FromType::<MyResource>::from_type()); let data = registry.data::<ReflectResource>().unwrap(); // Same with resources let component_id = data.register_resource(&mut world); // They match assert_eq!(component_id, world.resource_id::<MyResource>().unwrap()); ```
robtfm
pushed a commit
to robtfm/bevy
that referenced
this pull request
Oct 4, 2024
# Objective - bevyengine#15496 introduced documentation with some missing links. ## Solution - Add the missing links and clean up a little.
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
ReflectComponent/Resource#15453Solution
World::resource_idandWorld::register_resourcemethods to support this featureReflectResource::register_resourcemethod, and new pointer to this new functionReflectComponent::register_componentTesting
Showcase