bevyengine / bevyengine/bevy

Make asset handles `!Default`

Open
#2,647 7 comments 1 reaction 0 assignees View on GitHub
A-Assets C-Usability X-Needs-SME
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?

[Handle](https://github.com/bevyengine/bevy/blob/b13472dae495ecc7d1a80cbe1ad12718c0de9262/crates/bevy_asset/src/handle.rs#L61) currently requires `Default` to be implemented, which reduces type safety because for many `Assets` no default makes sense. Removing this requirement would also partially solve #1201, because when creating `Text` and filling out the values with `..Default::default()` `style.font` will be set to an invalid font Handle and fail to render.

## What solution would you like?

The removal of the requirement that all `Handles` have to implement `Default`. The reason this requirement exists is because `Handle` derives `Reflect`.

## What alternative(s) have you considered?

Runtime errors for default handle values where `Default` is invalid, but this delays the problem feedback and increases iteration time compared to getting the error at compile time.

Contributor guide

Open the contributing guide

Research direction

Start with crates/bevy_asset/src/handle.rs at the linked Handle definition and inspect why it derives Reflect and requires Default. Trace the affected Handle and Assets usages, then verify that removing the Default requirement preserves reflection while preventing invalid default handles from compiling.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.