bevy/crates/bevy_asset/src
charlotte df14443db9
Add AssetChanged query filter (#16810)
# Objective

Implement a new `AssetChanged` query filter that allows users to query
for entities whose related assets may have changed.

- Closes https://github.com/bevyengine/bevy/issues/5069
- Unblocks #16420. Currently, `cold-specialization`, a key rendering
optimization for unlocking ancillary benefits of the retained render
world, is blocked on being unable detect all scenarios in which an
entity's mesh/material changes using events and observers. An
`AssetChanged` filter will drastically simplify our implementation and
be more robust to future changes.

Originally implemented by @nicopap in #5080.

## Solution

- Adds a new `AssetChanged` query filter that initializes a
`AssetChanges<A>` resource that tracks changed assets and ticks in
`asset_events`.
- ~Reverts #13343 and changes the api of `get_state` to accept `impl
Into<UnsafeWorldCell<'w>>` to allow accessing the `AssetChanges<A>`
resource.~
- Adds a `AsAssetId` trait used for newtype handle wrappers (e.g.
`Mesh3d`) that allows associating a component with the underlying
`Asset` it represents.

## Testing

- Tests are added for `AssetChanged`.
- TBD on performance. We are going to add this `Mesh3d` and
`MeshMaterial3d` (etc) in the renderer. Long term wins in render
performance this unblocks should swamp tracking overhead for any
realistic workload.

## Migration Guide

- The `asset_events` system is no longer public. Users should order
their systems relative to the `AssetEvents` system set.

---------

Co-authored-by: Nicola Papale <nico@nicopap.ch>
Co-authored-by: Patrick Walton <pcwalton@mimiga.net>
Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
Co-authored-by: Chris Russell <8494645+chescock@users.noreply.github.com>
2024-12-17 18:57:08 +00:00
..
io Update hashbrown to 0.15 (#15801) 2024-12-10 19:45:50 +00:00
processor Remove the meta field from LoadedAsset and ErasedLoadedAsset. (#15487) 2024-12-13 20:40:02 +00:00
server Remove the meta field from LoadedAsset and ErasedLoadedAsset. (#15487) 2024-12-13 20:40:02 +00:00
asset_changed.rs Add AssetChanged query filter (#16810) 2024-12-17 18:57:08 +00:00
assets.rs Add AssetChanged query filter (#16810) 2024-12-17 18:57:08 +00:00
direct_access_ext.rs Add methods to directly load assets from World (#12023) 2024-02-27 00:28:26 +00:00
event.rs fix: add reflect to SceneInstanceReady and other observers/events (#16018) 2024-10-20 13:51:41 +00:00
folder.rs Bevy Asset V2 (#8624) 2023-09-07 02:07:27 +00:00
handle.rs Update hashbrown to 0.15 (#15801) 2024-12-10 19:45:50 +00:00
id.rs Update hashbrown to 0.15 (#15801) 2024-12-10 19:45:50 +00:00
lib.rs Add AssetChanged query filter (#16810) 2024-12-17 18:57:08 +00:00
loader_builders.rs Remove the meta field from LoadedAsset and ErasedLoadedAsset. (#15487) 2024-12-13 20:40:02 +00:00
loader.rs Fix stale comment on LoadContext::finish. (#16821) 2024-12-15 19:18:03 +00:00
meta.rs Cleanup unneeded lifetimes in bevy_asset (#15546) 2024-09-30 21:54:59 +00:00
path.rs Deny derive_more error feature and replace it with thiserror (#16684) 2024-12-06 17:03:55 +00:00
reflect.rs Add core and alloc over std Lints (#15281) 2024-09-27 00:59:59 +00:00
render_asset.rs Split off bevy_image from bevy_render (#15650) 2024-10-04 20:16:47 +00:00
saver.rs Cleanup unneeded lifetimes in bevy_asset (#15546) 2024-09-30 21:54:59 +00:00
transformer.rs Add core and alloc over std Lints (#15281) 2024-09-27 00:59:59 +00:00