Skip to content

Optional Bundle Members #759

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

Closed
Zeenobit opened this issue Oct 14, 2023 · 1 comment
Closed

Optional Bundle Members #759

Zeenobit opened this issue Oct 14, 2023 · 1 comment

Comments

@Zeenobit
Copy link

As Bevy 0.11, this does not compile:

#[derive(Bundle)]
struct Foo {
    bar: Option<Bar>,
    ...
}

#[derive(Component)]
struct Bar;

This means it's impossible express bundles with "optional components". The workaround is to create distinct types for variations with/without the optional components:

#[derive(Bundle)]
struct Foo {
    ...
}


#[derive(Bundle)]
struct FooWithBar {
   bar: Bar,
   ...
}

Ideally, bundles should allow optional components/bundles as their members. This would eliminate some code duplication for the user and allow them to express optional components more explicitly and ergonomically.

During insertion, the bundle could check for None values and not insert those components.
During removal, the component would be removed if it exists, which I believe is already the existing behavior.

@alice-i-cecile
Copy link
Member

Duplicate of bevyengine/bevy#2157 <3 This is the website for the book / release notes etc, not the engine, so that's probably why you didn't find the duplicate.

@alice-i-cecile alice-i-cecile closed this as not planned Won't fix, can't repro, duplicate, stale Oct 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants