Skip to content

Conversation

andriyDev
Copy link
Contributor

@andriyDev andriyDev commented Oct 2, 2025

Objective

  • Previously, asset processors needed to be fully specified. This meant writing met files by hand was incredibly cumbersome.
  • In addition, using core::any::type_name is generally undesirable since it is only intended for debugging.

Solution

  • Require TypePath impl on AssetLoader, AssetTransformer, AssetSaver, and AssetProcessor.
  • Register loaders and processors by their TypePath::type_path. This makes the path format stable.
  • Additionally register the processors by their TypePath::short_type_path, and ensure there are no other processors with the same short_type_path. If a user tries to use an ambiguous short type path, we list out all full type paths.

Note: I left doing this with asset loaders as a future PR. There's more complexity there (since we have to deal with pre-registering asset loaders), and this seems like the bigger "bang for our buck".

Testing

  • I ran the asset_processing example. No change.
  • I changed the asset processing example to use the short type path. It still behaved as expected.
  • I created a new AssetTransformer in asset_processing::sneaky::CoolTextTransformer and a new processor that looked identical to the regular one (but using the sneaky transformer). It printed an error, listing out the full paths of both processors!

@andriyDev andriyDev requested a review from JMS55 October 2, 2025 08:00
@andriyDev andriyDev added A-Assets Load files from disk to use for things like images, models, and sounds C-Usability A targeted quality-of-life change that makes Bevy easier to use D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Oct 2, 2025
@andriyDev andriyDev added this to the 0.18 milestone Oct 2, 2025
@andriyDev andriyDev force-pushed the short-processors branch 3 times, most recently from bc052c7 to fc361d5 Compare October 2, 2025 08:19
@JMS55 JMS55 added M-Needs-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide M-Needs-Release-Note Work that should be called out in the blog due to impact labels Oct 2, 2025
Copy link
Contributor

github-actions bot commented Oct 2, 2025

It looks like your PR has been selected for a highlight in the next release blog post, but you didn't provide a release note.

Please review the instructions for writing release notes, then expand or revise the content in the release notes directory to showcase your changes.

Copy link
Contributor

github-actions bot commented Oct 2, 2025

It looks like your PR is a breaking change, but you didn't provide a migration guide.

Please review the instructions for writing migration guides, then expand or revise the content in the migration guides directory to reflect your changes.

Copy link
Contributor

@JMS55 JMS55 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code lgtm!

Please add a migration guide for the TypePath changes, and a release note entry showcasing this work.

Also, while I won't block on it, it would be great to have a unit test for ambiguous processor names. I'm worried that that is easy to break in future code changes.

@JMS55 JMS55 requested a review from cart October 2, 2025 14:57
@JMS55
Copy link
Contributor

JMS55 commented Oct 2, 2025

Also check the CI jobs. Looks like you need to add the TypePath derive to some more stuff.

@andriyDev andriyDev force-pushed the short-processors branch 4 times, most recently from 05c0cc2 to e266eed Compare October 3, 2025 02:56
@andriyDev andriyDev requested a review from JMS55 October 3, 2025 02:59
@andriyDev andriyDev force-pushed the short-processors branch 2 times, most recently from 0062acb to 0fd8d69 Compare October 3, 2025 03:10
@andriyDev
Copy link
Contributor Author

Fixed up CI, added the migration guide + release notes, and also added tests for getting the processor by name. We definitely need more testing around asset processing itself (I'm only testing that getting the processor by name all works), but that should be a different PR.

@ChristopherBiscardi
Copy link
Contributor

I think this is the first Bevy feature that will allow previously written assets (I guess .meta files in this case) to break when installing a new plugin. (ex: if that plugin also includes an ImageLoader, or CoolTextLoader in the example here). So the general guidance will probably become "namespace your loaders" like MyCrateImageLoader since this is now a global namespace, which doesn't really change the amount of handwritten code. We're moving the namespacing from the module path to a human-curated prefix.

This may also be introducing a difference in behavior between other types and loaders, ex: the scenes example asset currently requires full type paths for components, Resources, etc

I don't have a strong feeling either way (slight preference for adding new plugins not being able to break current applications), but I do see "why can I wrote loaders with shortnames but not components" coming up and we should have an answer for it.

@hukasu
Copy link
Contributor

hukasu commented Oct 4, 2025

Deriving TypePath should already namespace the type, no?

@andriyDev
Copy link
Contributor Author

Deriving TypePath should already namespace the type, no?

Only if you use long type names. If you use short type names, then there's a risk that something like ImageLoader may be aliased by some other plugin that adds its own ImageLoader. So if you write your meta file to point to ImageLoader, it's more at risk of failing with an error, but if you name your loader MyExtraSpecialImageLoader, there's a smaller risk.

I still think this is a win. I don't think it's desirable for users to have to specify the module path since that can include info that doesn't matter to them, like LoadTransformAndSave is stored in bevy_asset::processor.

@hukasu
Copy link
Contributor

hukasu commented Oct 4, 2025

ah, so the comment was about namespacing it on the .meta files, right

@andriyDev
Copy link
Contributor Author

The comment was that rather than calling their loaders ImageLoader the recommendation will be to "fake namespace" by saying MyExtraSpecialImageLoader. Which means the long name might look like: my_extra_special_crate::MyExtraSpecialImageLoader.

@JMS55
Copy link
Contributor

JMS55 commented Oct 7, 2025

Sorry, not going to have time to review this for a bit. Hopefully other community members can help with reviews.

@andriyDev
Copy link
Contributor Author

Rebased and added a test in lib.rs showing that short type names work!

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 targeted quality-of-life change that makes Bevy easier to use D-Straightforward Simple bug fixes and API improvements, docs, test and examples M-Needs-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide M-Needs-Release-Note Work that should be called out in the blog due to impact S-Needs-Review Needs reviewer attention (from anyone!) to move forward
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants