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

Allow Creating Custom AssetIO Implementations That Support Hot Reload #1414

Closed
zicklag opened this issue Feb 7, 2021 · 5 comments
Closed
Labels
A-Assets Load files from disk to use for things like images, models, and sounds C-Enhancement A new feature

Comments

@zicklag
Copy link
Member

zicklag commented Feb 7, 2021

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

Currently, when creating your own AssetIo implementation, it is actually impossible to implement a custom equivalent to the filesystem_watcher_sysem, because that function depends on asset_server.server.asset_io, which is a private field of AssetServer.

In my use-case, I am creating a custom AssetIo implementation that allows loading assets from zip bundles, but I want to fall back completely to the default asset loader. Unfortunately, when I did this, I lost the ability to do hot reload, because the built-in filesystem_watcher_system will only work when the current AssetIo implementation is FileAssetIo.

What solution would you like?

I don't have a specific idea for the implementation, but however necessary, I need a way to be able to copy the exact functionality of the current filesystem_watcher_system in my own AssetIo implementation.

What alternative(s) have you considered?

Waiting on the Distil integration? 🤷‍♂️ But I would like to get this into my app now, so I'd hope there's at least a short-term solution would could come up with now.

Additional context

If the strategy doesn't require a ton of work, I'd be willing to try to do this, but I'm not exactly sure what the best strategy is. The obvious easy techinque would just be to make the types that are necessary to access public types instead of private, but I'm not sure that is the best long-term design. Also, with the integration with Distil comming up, I'm not sure if we need it to be a great long term solution?

Anyway, I need some directional guidance on how we want to go about this.

@alice-i-cecile alice-i-cecile added A-Assets Load files from disk to use for things like images, models, and sounds C-Enhancement A new feature labels Feb 16, 2021
@johanhelsing
Copy link
Contributor

Was struggling with this today. @zicklag did you figure out a way around it?

@zicklag
Copy link
Member Author

zicklag commented Sep 19, 2021

No, I never made any progress with this.

@johanhelsing
Copy link
Contributor

Looked at this again today. AssetServer::asset_io was added in 0.7 (98938a8), which makes it possible to get the AssetIO and downcast it to FileAssetIo yourself. However, It's still not possible to replicate the default implementation (filesystem_watcher_system) because FileAssetIo::filesystem_watcher is private and has no getter.

@Neopallium
Copy link
Contributor

Neopallium commented Jun 27, 2022

It is now possible to re-implement "watch for changes" support in custom AssetIo implementations. It should be possible to reuse the FilesystemWatcher in custom AssetIo impls, but it does require copying some code from FileAssetIo.

This PR [0] merged a public method AssetServer::reload_asset which can be used to trigger the reloads as is done in filesystem_watcher_system. The reload_asset method can be used for more specialized reloaders too (network event, editor "deploy" trigger, etc..).

I have this working in my custom AssetIo that works like bevy_web_asset crate.

  1. [Merged by Bors] - Add reload_asset method to AssetServer. #5106

@zicklag
Copy link
Member Author

zicklag commented Jun 27, 2022

Sounds good, thank you!

@zicklag zicklag closed this as completed Jun 27, 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-Enhancement A new feature
Projects
None yet
Development

No branches or pull requests

4 participants