Imposible to create custom Resource via register_component_with_descriptor
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 22h
- Merged PRs (30d)
- 161
Description
## Bevy version and features
0.19.x
## What you did
I'm trying to create a resource manually using [register_component_with_descriptor](https://docs.rs/bevy_ecs/latest/bevy_ecs/world/struct.World.html#method.register_component_with_descriptor).
## What went wrong
Starting with version 0.19, resources have become components. They require the [IsResource](https://docs.rs/bevy_ecs/latest/bevy_ecs/resource/struct.IsResource.html) component.
There is no way to add the required components to custom components. Consequently, it is not possible to create custom resources.
## Additional information
Related to #19731
Steps to reproduce:
```rust
use bevy_ecs::change_detection::MaybeLocation;
use bevy_ecs::component::{ComponentCloneBehavior, ComponentDescriptor, StorageType};
use bevy_ecs::prelude::*;
use bevy_ptr::OwningPtr;
use std::alloc::Layout;
struct MyResource;
let mut world = World::new();
let resource_component_id = world.register_component_with_descriptor(unsafe {
ComponentDescriptor::new_with_layout(
"MyResource",
StorageType::Table,
Layout::new::(),
None,
true,
ComponentCloneBehavior::Default,
None,
)
});
let caller = MaybeLocation::caller();
OwningPtr::make(MyResource, |value| unsafe {
world.insert_resource_by_id(resource_component_id, value, caller)
});
let option_ptr = world.get_resource_by_id(resource_component_id);
assert!(option_ptr.is_some()); // You cannot obtain a resource for which there is no IsResource.
```
Contributor guide
Research direction
Start by tracing register_component_with_descriptor, insert_resource_by_id, and get_resource_by_id in bevy_ecs, then read how IsResource is applied and checked. Reproduce the example from the issue and inspect related issue #19731. Done means a resource registered through the descriptor API can be inserted and retrieved successfully, with coverage for the custom-resource path.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- game-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100