bevyengine / bevyengine/bevy

`#[reflect(Default)]` for generic when `T: Default` only

Open
#8,218 3 comments 0 reactions 0 assignees View on GitHub
A-Reflection C-Feature C-Usability
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 22h
Merged PRs (30d)
161

Description

## What problem does this solve or what need does it fill?

`bevy_inspector_egui` in its inspector complains that it cannot instantiate a new value for my generic type because it's missing `#[reflect(Default)]`. But the generic type only implements `Default` if the parameter `T` does:

```rust
#[derive(Reflect, FromReflect)]
// #[reflect(Default)] //< Doesn't work obviously
struct MyType { ... }

impl Default for MyType { ... }
```

## What solution would you like?

Have a way to do what `#[reflect(Default)]` does but manually, whatever that is (I have no idea where all those `#[reflect(xxx)]` are documented).

## What alternative(s) have you considered?

I don't know of any.

See discussion on Discord: https://discord.com/channels/691052431525675048/742569353878437978/1089576631594668115

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.