bevyengine / bevyengine/bevy

insert_default method for ReflectComponent and ReflectResource

Open
#5,592 2 comments 0 reactions 0 assignees View on GitHub
A-Reflection C-Feature
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?

There are cases where we would like to spawn a default version of the component/resource,

## What solution would you like?

having `insert_default(&self, entity)` and `insert_default(&self)` methods would make this possible ergonomically and more efficiently.

## What alternative(s) have you considered?

Using `ReflectDefault` to create a `Box` and then using `insert`, however this both:
- Boxes the value
- Already calls from_world within `insert` meaning you duplicate the default call

This is not very efficient, or ergonomic

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.