Spawning/inserting a resource should replace existing resources instead of bouncing
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 16h
- Merged PRs (30d)
- 171
Description
## What problem does this solve or what need does it fill?
When spawning/inserting an already existing resource it will error.
```
2026-05-07T20:04:32.358321Z WARN bevy_ecs::resource: Tried inserting the resource while one already exists.
Resources are unique components stored on a single entity.
Inserting on a different entity, when one already exists, causes the new value to be removed.
```
However this doesn't align with the current behaviour of `init_resource`/`insert_resource`.
This makes spawning resources with extra components difficult.
```rust
// This works perfectly.
commands.insert_resource(Level(1));
// But this doesn't
commands.spawn((
Name::new("Level"),
Level(2)
));
// unless you remove the resource first.
commands.remove_resource::();
commands.spawn((
Name::new("Level"),
Level(3)
));
```
## What solution would you like?
Either
- Change `init_resource`/`insert_resource` to fail if it already exists
- Change `spawn(Resource)` to replace the existing resource.
Contributor guide
Research direction
Start by tracing the Commands APIs named in the issue: insert_resource, init_resource, spawn, and remove_resource, then compare how each handles an existing resource. Done means the chosen behavior is consistent for direct insertion and spawning with extra components, with coverage for the existing-resource case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- game-dev
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100