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

Support hot-reloading for a const HandleUntyped handle to an asset #3660

Closed
superdump opened this issue Jan 13, 2022 · 1 comment
Closed
Assignees
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 C-Usability A targeted quality-of-life change that makes Bevy easier to use

Comments

@superdump
Copy link
Contributor

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

I would like to make the core shaders hot-reloadable, behind a feature. So by default bevy would use include_str!() but it could optionally use something like asset_server.load() instead.

What solution would you like?

I want to be able to associate something like:

pub const PBR_SHADER_HANDLE: HandleUntyped =
    HandleUntyped::weak_from_u64(Shader::TYPE_UUID, 4805239651767701046);

with an asset loaded and watched by the AssetServer, so the PBR_SHADER_HANDLE can be used as the handle, but so that the asset server file watcher will watch for changes and notify PBR_SHADER_HANDLE when the asset was changed.

Additional context

  • Hot-reloading works by notifying the HandleId that can be created from the AssetPath (via the AssetPathId). This means that only the handle created from the AssetPath can be notified.
  • There can only be one handle to an asset. I have been trying to make it so that there can be multiple handles, so that the const HandleUntyped can also be associated with the asset, and will be notified of changes but this seems to be way more difficult than expected.
    • Note that loading the asset and then using asset_server.set_untracked() to set the HandleUntyped for the asset will not support hot-reloading because only the HandleId calculated from the AssetPath will be notified.
@superdump superdump 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 C-Usability A targeted quality-of-life change that makes Bevy easier to use labels Jan 13, 2022
@superdump
Copy link
Contributor Author

I made a PR as an attempt at this: #3673

@superdump superdump self-assigned this Jan 16, 2022
@bors bors bot closed this as completed in 98938a8 Feb 18, 2022
molikto pushed a commit to molikto/bevy that referenced this issue Feb 20, 2022
Adds "hot reloading" of internal assets, which is normally not possible because they are loaded using `include_str` / direct Asset collection access.

This is accomplished via the following:
* Add a new `debug_asset_server` feature flag
* When that feature flag is enabled, create a second App with a second AssetServer that points to a configured location (by default the `crates` folder). Plugins that want to add hot reloading support for their assets can call the new `app.add_debug_asset::<T>()` and `app.init_debug_asset_loader::<T>()` functions.
* Load "internal" assets using the new `load_internal_asset` macro. By default this is identical to the current "include_str + register in asset collection" approach. But if the `debug_asset_server` feature flag is enabled, it will also load the asset dynamically in the debug asset server using the file path. It will then set up a correlation between the "debug asset" and the "actual asset" by listening for asset change events.

This is an alternative to bevyengine#3673. The goal was to keep the boilerplate and features flags to a minimum for bevy plugin authors, and allow them to home their shaders near relevant code. 

This is a draft because I haven't done _any_ quality control on this yet. I'll probably rename things and remove a bunch of unwraps. I just got it working and wanted to use it to start a conversation.

Fixes bevyengine#3660
kurtkuehnert pushed a commit to kurtkuehnert/bevy that referenced this issue Mar 6, 2022
Adds "hot reloading" of internal assets, which is normally not possible because they are loaded using `include_str` / direct Asset collection access.

This is accomplished via the following:
* Add a new `debug_asset_server` feature flag
* When that feature flag is enabled, create a second App with a second AssetServer that points to a configured location (by default the `crates` folder). Plugins that want to add hot reloading support for their assets can call the new `app.add_debug_asset::<T>()` and `app.init_debug_asset_loader::<T>()` functions.
* Load "internal" assets using the new `load_internal_asset` macro. By default this is identical to the current "include_str + register in asset collection" approach. But if the `debug_asset_server` feature flag is enabled, it will also load the asset dynamically in the debug asset server using the file path. It will then set up a correlation between the "debug asset" and the "actual asset" by listening for asset change events.

This is an alternative to bevyengine#3673. The goal was to keep the boilerplate and features flags to a minimum for bevy plugin authors, and allow them to home their shaders near relevant code. 

This is a draft because I haven't done _any_ quality control on this yet. I'll probably rename things and remove a bunch of unwraps. I just got it working and wanted to use it to start a conversation.

Fixes bevyengine#3660
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 C-Usability A targeted quality-of-life change that makes Bevy easier to use
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

1 participant