Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to ignore field of bundle #5559

Closed
alice-i-cecile opened this issue Aug 3, 2022 · 4 comments · Fixed by #5578 or #5579
Closed

Add ability to ignore field of bundle #5559

alice-i-cecile opened this issue Aug 3, 2022 · 4 comments · Fixed by #5578 or #5579
Labels
A-ECS Entities, components, systems, and events C-Usability A targeted quality-of-life change that makes Bevy easier to use D-Trivial Nice and easy! A great choice to get started with Bevy

Comments

@alice-i-cecile
Copy link
Member

alice-i-cecile commented Aug 3, 2022

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

Add the ability to ignore a field of a bundle using the #[derive(Bundle)] macro, causing it to not be included in the generated list of components.

This is primarily useful when working with PhantomData.

What solution would you like?

#[derive(Bundle)]
struct GenericBundle<T>{
 transform: Transform,
  #[bundle(ignore)]
  _phantom: PhantomData<T>,
}

Modify the derive Bundle macro to accomplish this :)

Be sure to add this to the Bundle docs as a doc test so this keeps working and can be discovered.

@alice-i-cecile alice-i-cecile added D-Trivial Nice and easy! A great choice to get started with Bevy A-ECS Entities, components, systems, and events C-Usability A targeted quality-of-life change that makes Bevy easier to use labels Aug 3, 2022
@mockersf
Copy link
Member

mockersf commented Aug 3, 2022

We already have a #[bundle] attribute, it could be confusing to add a #[bundle(ignore)]. Feel free to find better names either for the existing one or the new one 🙂

@alice-i-cecile
Copy link
Member Author

IMO we should be hygienic and use #[bundle(nest)] to be clearer about what's going on and keep a quasi-namespace for the trait.

@LegNeato
Copy link
Contributor

LegNeato commented Aug 4, 2022

Serde uses "skip" fwiw

@maccesch
Copy link
Contributor

maccesch commented Aug 5, 2022

Almost finished implementing this but I just realized that if you add a #[bundle(ignore)] to a field, this field type has to implement Default or we can't initialize it in the from_components() method that is generated in the macro.

Or am I missing sth here?

bors bot pushed a commit that referenced this issue Oct 24, 2022
# Objective

Fixes #5559

Replaces #5628

## Solution

Because the generated method from_components() creates an instance of Self my implementation requires any field type that is marked to be ignored to implement Default.

---

## Changelog

Added the possibility to ignore fields in a bundle with `#[bundle(ignore)]`. Typically used when `PhantomData` needs to be added to a `Bundle`.
@bors bors bot closed this as completed in 7a41efa Oct 24, 2022
james7132 pushed a commit to james7132/bevy that referenced this issue Oct 28, 2022
# Objective

Fixes bevyengine#5559

Replaces bevyengine#5628

## Solution

Because the generated method from_components() creates an instance of Self my implementation requires any field type that is marked to be ignored to implement Default.

---

## Changelog

Added the possibility to ignore fields in a bundle with `#[bundle(ignore)]`. Typically used when `PhantomData` needs to be added to a `Bundle`.
Pietrek14 pushed a commit to Pietrek14/bevy that referenced this issue Dec 17, 2022
# Objective

Fixes bevyengine#5559

Replaces bevyengine#5628

## Solution

Because the generated method from_components() creates an instance of Self my implementation requires any field type that is marked to be ignored to implement Default.

---

## Changelog

Added the possibility to ignore fields in a bundle with `#[bundle(ignore)]`. Typically used when `PhantomData` needs to be added to a `Bundle`.
ItsDoot pushed a commit to ItsDoot/bevy that referenced this issue Feb 1, 2023
# Objective

Fixes bevyengine#5559

Replaces bevyengine#5628

## Solution

Because the generated method from_components() creates an instance of Self my implementation requires any field type that is marked to be ignored to implement Default.

---

## Changelog

Added the possibility to ignore fields in a bundle with `#[bundle(ignore)]`. Typically used when `PhantomData` needs to be added to a `Bundle`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ECS Entities, components, systems, and events C-Usability A targeted quality-of-life change that makes Bevy easier to use D-Trivial Nice and easy! A great choice to get started with Bevy
Projects
None yet
4 participants