Skip to content

Hashmap visit asset dependencies impl#23566

Merged
alice-i-cecile merged 2 commits intobevyengine:mainfrom
RylanYancey:hashmap-visit-asset-dependencies-impl
Mar 29, 2026
Merged

Hashmap visit asset dependencies impl#23566
alice-i-cecile merged 2 commits intobevyengine:mainfrom
RylanYancey:hashmap-visit-asset-dependencies-impl

Conversation

@RylanYancey
Copy link
Copy Markdown
Contributor

Objective

  • Allow tagging of HashMaps with #[dependency], for assets which contain variable binding assignments to asset handles.

Solution

  • The solution is to create an implementation of VisitAssetDependencies for HashMap that behaves similarly to HashSet.

Testing

  • The changes were tested by adding map_handles and untyped_map_handles to StructTestAsset and EnumTestAsset. Then, cargo test was ran in crates/bevy_asset.

Showcase

I plan to use this to create a map of material bindings to material handles. In the below example, materials is a map of bindings (e.g. "$east", "$south"). Each Element contains up to six references, so this helps when there are block templates that only use one material for all faces.

#[derive(Asset, Reflect, Clone)]
#[type_path = "ovx::blocks::template"]
#[type_name = "BlockTemplate"]
pub struct BlockTemplate {
    #[dependency]
    pub inherits: Vec<Handle<BlockTemplate>>,
    #[dependency]
    pub materials: HashMap<String, Handle<BlockMaterial>>,
    pub elements: HashMap<String, Element>,
    pub variants: HashMap<String, Variant>,
    pub states: HashMap<String, BlockState>,
}

@github-actions
Copy link
Copy Markdown
Contributor

Welcome, new contributor!

Please make sure you've read our contributing guide, as well as our policy regarding AI usage, and we look forward to reviewing your pull request shortly ✨

@alice-i-cecile alice-i-cecile added D-Trivial Nice and easy! A great choice to get started with Bevy 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 Mar 29, 2026
@github-project-automation github-project-automation bot moved this to Needs SME Triage in Assets Mar 29, 2026
@alice-i-cecile alice-i-cecile added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Mar 29, 2026
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Mar 29, 2026
Merged via the queue into bevyengine:main with commit 3286b61 Mar 29, 2026
47 checks passed
@github-project-automation github-project-automation bot moved this from Needs SME Triage to Done in Assets Mar 29, 2026
splo pushed a commit to splo/bevy that referenced this pull request Mar 31, 2026
# Objective

- Allow tagging of HashMaps with `#[dependency]`, for assets which
contain variable binding assignments to asset handles.

## Solution

- The solution is to create an implementation of VisitAssetDependencies
for HashMap that behaves similarly to HashSet.

## Testing

- The changes were tested by adding `map_handles` and
`untyped_map_handles` to `StructTestAsset` and `EnumTestAsset`. Then,
`cargo test` was ran in `crates/bevy_asset`.

## Showcase
I plan to use this to create a map of material bindings to material
handles. In the below example, `materials` is a map of bindings (e.g.
"$east", "$south"). Each `Element` contains up to six references, so
this helps when there are block templates that only use one material for
all faces.

```rust
#[derive(Asset, Reflect, Clone)]
#[type_path = "ovx::blocks::template"]
#[type_name = "BlockTemplate"]
pub struct BlockTemplate {
    #[dependency]
    pub inherits: Vec<Handle<BlockTemplate>>,
    #[dependency]
    pub materials: HashMap<String, Handle<BlockMaterial>>,
    pub elements: HashMap<String, Element>,
    pub variants: HashMap<String, Variant>,
    pub states: HashMap<String, BlockState>,
}
```
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-Trivial Nice and easy! A great choice to get started with Bevy 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: Done

Development

Successfully merging this pull request may close these issues.

2 participants