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

Make asset handles !Default #2647

Open
RedlineTriad opened this issue Aug 13, 2021 · 7 comments
Open

Make asset handles !Default #2647

RedlineTriad opened this issue Aug 13, 2021 · 7 comments
Labels
A-Assets Load files from disk to use for things like images, models, and sounds C-Usability A simple quality-of-life change that makes Bevy easier to use X-Controversial There is active debate or serious implications around merging this PR

Comments

@RedlineTriad
Copy link
Contributor

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

Handle currently requires Default to be implemented, which reduces type safety because for many Assets no default makes sense. Removing this requirement would also partially solve #1201, because when creating Text and filling out the values with ..Default::default() style.font will be set to an invalid font Handle and fail to render.

What solution would you like?

The removal of the requirement that all Handles have to implement Default. The reason this requirement exists is because Handle derives Reflect.

What alternative(s) have you considered?

Runtime errors for default handle values where Default is invalid, but this delays the problem feedback and increases iteration time compared to getting the error at compile time.

@RedlineTriad RedlineTriad added C-Enhancement A new feature S-Needs-Triage This issue needs to be labelled labels Aug 13, 2021
@alice-i-cecile
Copy link
Member

#1395 is related, covering a Default-like trait specifically designed for structs created via reflection (such as objects loaded from scenes).

@alice-i-cecile alice-i-cecile added A-Assets Load files from disk to use for things like images, models, and sounds A-Reflection Runtime information about types C-Usability A simple quality-of-life change that makes Bevy easier to use and removed C-Enhancement A new feature S-Needs-Triage This issue needs to be labelled A-Reflection Runtime information about types labels Aug 13, 2021
@NiklasEi
Copy link
Member

NiklasEi commented Aug 13, 2021

I agree that the default impl for all handles reduces type safety. I am wondering though whether removing it would reduce the usibility of many build-in bundles (at least if that also means the bundles themself no longer are Default).

If there is no longer a default for the font handle in the text bundle, can there still be a default for the bundle? In the case of fonts this might be solved with ongoing discussions about bundling fonts/using system fonts (#1017, #1325), but the same problem arises with other bundles. E.g. is there a default for sprite bundle if there is no default for material handles?

One idea: we could have convenience functions like with_font or with_material that still allow using default values for all other fields. But this is still not as nice to use as the current ..Default::default().

@RedlineTriad
Copy link
Contributor Author

I agree that the default impl for all handles reduces type safety. I am wondering though whether removing it would reduce the usibility of many build-in bundles (at least if that also means the bundles themself no longer are Default).

It is only the requirement I care about. If a default font is added that can be used, and Default implemented. But it shouldn't be required to be implemented for all assets, even those where no such reasonable default exists.

@NiklasEi
Copy link
Member

Only lifting the requirement would not improve your example of the Text bundle. We should then also rethink defaults for all bundles.

But just lifting the requirement sounds reasonable as a first step 👍

@RedlineTriad
Copy link
Contributor Author

Only lifting the requirement would not improve your example of the Text bundle. We should then also rethink defaults for all bundles.

Sorry, what I wrote was a bit misleading. I do care about removing the Default implementations, but only where they don't currently make sense,
such as Text.
So I want Default to be optional and implemented where a reasonable default exists; and not where it doesn't.

@mockersf
Copy link
Member

While I would like to remove the Default impl for Handle<T> as it indeed doesn't make sense, it would break what is currently the favoured api (using ..Default::default()).

It could be useful to list all cases where a bundle has an handle component, and see what default could be used there

  • Handle<Texture> -> Bevy logo?
  • Handle<Mesh> -> a cube?
  • ...

@RedlineTriad
Copy link
Contributor Author

* `Handle<Texture>` -> Bevy logo?

It is common to have some kind of very obvious missing texture, like fully saturated purple, maybe even checkered to make it even more obvious.
image

@alice-i-cecile alice-i-cecile added the X-Controversial There is active debate or serious implications around merging this PR label Jul 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Assets Load files from disk to use for things like images, models, and sounds C-Usability A simple quality-of-life change that makes Bevy easier to use X-Controversial There is active debate or serious implications around merging this PR
Projects
Status: Concrete and Controversial
Development

No branches or pull requests

4 participants