bevyengine / bevyengine/bevy

Despawning resource entities

Open
#24,330 2 comments 4 reactions 0 assignees View on GitHub
A-ECS C-Feature D-Complex S-Needs-Design
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?

Resources are now components on entities, but you're not allowed to simply despawn those entities.

## What solution would you like?

You should be able to despawn resource entities like regular entities.

One benefit to this is that you get to re-use the mechanism for state-scoped entities for resources:

```rust
#[derive(Resource)]
#[require(DespawnOnExit(AppState::InGame))]
struct Score(u32);
```

## What alternative(s) have you considered?

Specially treat resource entities by calling `World::remove_resource`.

## Additional context

> You can still have Stable Id's for Resource Entities, If we have Custom Allocators, which I would assume, could choose to not free the Index when despawning, and then when attempting to respawn, if its been spawned before then reuse the Index.
Then you could have Relations/Systems that despawn Resource Entities.
>
> Although perhaps the intention is more so, not-existing at any point is an error.

\- @Diddykonga from [this Discord discussion](https://discord.com/channels/691052431525675048/749335865876021248/1505341036464181278)

Contributor guide

Open the contributing guide

Research direction

The issue names no files or tests. Start by locating the entity-despawn path and the handling of resource entities, then determine how state-scoped despawning could use the same mechanism. Done means resource entities can be despawned like regular entities without breaking resource access or lifecycle behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
game-dev
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.