bevyengine / bevyengine/bevy

Make `Visibility` optional in most built-in systems

Open
#5,258 9 comments 0 reactions 0 assignees View on GitHub
A-Rendering 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?

Many built-in systems (_e.g._ [`extract_text2d_sprite()`](https://docs.rs/bevy/latest/bevy/text/fn.extract_text2d_sprite.html) query a core component they want to update (_e.g._ `Text`) with an associated unconditional `Visibility` component. If removed, the system doesn't run on the `Entity`. However, most components (and especially the ones directly related to rendering) should be assumed visible by default. The ability to dynamically control the visibility of a render item should be an additional opt-in feature, not a default one.

## What solution would you like?

Replace `Visibility` with `Option` in the query of most built-in systems, and treat `None` as `Visibility::is_visible == true`.

```rust
if !maybe_visibility.map_or(true, |vis| vis.is_visible) {
continue; // skip this entity
}
```

## What alternative(s) have you considered?

Do nothing. This forces adding many unused `Visibility` components for all entities that are never going to be hidden (they might be deleted, but not dynamically shown/hidden).

## Additional context

The more "mandatory" components in a built-in system, the more difficult it is to reuse the built-in Bevy components. I'm trying to use `Text` to render some text, but with some properties (notably, the position, but also the visibility) controlled by my own framework. I could go rewrite from scratch a text rendering pipeline, but it feels like reusing the existing one is probably the best course of action. However currently the [`extract_text2d_sprite()`](https://docs.rs/bevy/latest/bevy/text/fn.extract_text2d_sprite.html) system forces adding 3 extra components in addition of `Text`, which I argue is too much and at least `Visibility` should be optional (if not others; alignment could also be made optional for the cases where there's no need to align).

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.