Skip to content

Conversation

@andriyDev
Copy link
Contributor

@andriyDev andriyDev commented Nov 20, 2025

Objective

Solution

  • Make the AssetPlugin include a DefaultAssetSource enum to initialize the default source when adding the AssetPlugin.
    • Note: DefaultAssetSource needs to contain a Mutex, since we need to be able to use the builder, but Plugin only provides us with a shared reference in the plugin.
  • Put a RwLock around the asset sources.
  • Add functions for adding and removing sources.
  • Make the existing register_asset_source only work for non-default sources, and have them just use the add/remove functions.
  • Temporary hack: prevent adding processed sources during runtime - we only allow unprocessed sources.
    • Practically, I don't expect users to want to add processed sources, but in the future they will. For this PR, I want to ignore that so we can solve 80% of the issues with 20% of the effort (I took a stab at making this work for processed sources too - it's possible but it's a pain).

One thing that is not addressed is the behavior after removing an asset source. This PR leaves it in a state where assets loaded from that asset source remain loaded. If you re-add the asset source, it does not reload the asset. But if the asset changes on the asset source, it should reload again. I'm kinda leaving it undefined since it's not clear what the correct behavior here should be anyway.

Testing

  • Added tests!

@andriyDev andriyDev force-pushed the runtime-sources branch 2 times, most recently from 3be29fa to 5528a8c Compare November 20, 2025 04:11
@andriyDev andriyDev added C-Feature A new feature, making something new possible A-Assets Load files from disk to use for things like images, models, and sounds D-Complex Quite challenging from either a design or technical perspective. Ask for help! S-Needs-Review Needs reviewer attention (from anyone!) to move forward M-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide M-Release-Note Work that should be called out in the blog due to impact labels Nov 20, 2025
@andriyDev andriyDev added this to the 0.18 milestone Nov 20, 2025
Copy link
Contributor

@greeble-dev greeble-dev left a comment

Choose a reason for hiding this comment

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

Couldn't spot any issues and tests passed. Just added some minor comments.

One thing I was left wondering about - do readers and writers still need to be passed to AssetSourceBuilder as closures that produce the value? I understand this was necessary when sources weren't shared. But is it true now that they're shared?

@andriyDev andriyDev force-pushed the runtime-sources branch 7 times, most recently from b8059fa to b980d56 Compare November 21, 2025 08:24
Copy link
Contributor

@kfc35 kfc35 left a comment

Choose a reason for hiding this comment

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

I read the whole thing and could not find any logical issues. Comments are just suggestions to improve readability / any future debugging. I also checked out your branch and also verified that tests pass. Thanks for adding such clear tests!

In case you wanted my 2c on expected behavior for asset server removal, what you said sounds reasonable. If you waaaanted to, you could note the behavior in your release notes but say that this behavior may change depending on community input and see if anyone says anything / has suggestions, but I leave that to you!

Copy link
Contributor Author

@andriyDev andriyDev left a comment

Choose a reason for hiding this comment

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

@kfc35

If you waaaanted to, you could note the behavior in your release notes

Yeah I considered this. I decided to avoid including it just because I'm sure everyone will have their own "obviously correct behavior", where some will be varying degrees of painful-to-implement. I don't think anyone will notice this weirdness for a long time. Kinda a bad reason, but I don't feel like opening that can of worms lol.

@andriyDev andriyDev added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Dec 5, 2025
@andriyDev andriyDev force-pushed the runtime-sources branch 2 times, most recently from 0c1fcfa to b5a9c12 Compare December 5, 2025 00:32
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Dec 9, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to a conflict with the base branch Dec 9, 2025
@andriyDev andriyDev force-pushed the runtime-sources branch 2 times, most recently from c829989 to 70d62c6 Compare December 12, 2025 19:03
@cart cart modified the milestones: 0.18, 0.19 Dec 16, 2025
@alice-i-cecile alice-i-cecile added S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged and removed S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it labels Dec 18, 2025
@alice-i-cecile
Copy link
Member

@andriyDev this isn't going to make 0.18, but when you get a chance can you resolve the merge conflicts?

@andriyDev
Copy link
Contributor Author

@alice-i-cecile Rebased! I also added an additional commit to clean up some cases that didn't need their own test setup, thanks to this PR. Fewer separate test setup code means we're less likely to accidentally start reading the FS again.

@andriyDev andriyDev added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged labels Dec 21, 2025
andriyDev and others added 20 commits December 22, 2025 17:09
Co-authored-by: Greeble <[email protected]>
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-Feature A new feature, making something new possible D-Complex Quite challenging from either a design or technical perspective. Ask for help! M-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide M-Release-Note Work that should be called out in the blog due to impact S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

Allow adding and removing asset sources at runtime. Custom AssetSource(s) must be registered before DefaultPlugins in order to work

5 participants