bevyengine / bevyengine/bevy

Allow the creation of handles from runtime values in bsn!

Open
#23,822 2 comments 0 reactions 0 assignees View on GitHub
A-Assets A-Scenes C-Feature D-Modest S-Blocked X-Uncontroversial
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 16h
Merged PRs (30d)
171

Description

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

You will still need to pass a handle from outside or add it manually in `template(...)`.

```rust
pub fn demo(atlas: Handle) -> impl Scene {
bsn! {
ImageNode {
image: "images/button.png",
texture_atlas: { TextureAtlasTemplate {
layout: HandleTemplate::Handle(atlas.clone()),
index: 0,
}},
}
}
}

// or
pub fn demo2() -> impl Scene {
bsn! {
template(|ctx| {
Ok(ImageNode {
image: ctx.resource::().load("images/button.png"),
texture_atlas: Some(TextureAtlas {
layout: ctx.resource_mut::>().add(
TextureAtlasLayout::from_grid(UVec2::new(65, 12), 1, 3, None, None)
),
index: 0,
}),
..default()
})
})
}
}
```

Allowing create a handle in-place when authoring a scene function. It is more ergonomic to compose related data of one component.

## What solution would you like?

Add a `HandleTemplate::Insert(...)` to create a handle directly from value.
```rust
pub fn demo() -> impl Scene {
bsn! {
ImageNode {
image: "images/button.png",
texture_atlas: { TextureAtlasTemplate {
layout: HandleTemplate::Insert(TextureAtlasLayout::from_grid(UVec2::new(65, 12), 1, 3, None, None)),
index: 0,
}},
}
}
}
```

## Additional context

This may also works when composing a bsn file, I think.

Contributor guide

Open the contributing guide

Research direction

Start by reading the bsn! and template handling around HandleTemplate, then inspect how runtime values are currently converted into handles. Compare the existing HandleTemplate::Handle path with the proposed HandleTemplate::Insert behavior and check the examples in the issue. Done means a handle can be created in place from a runtime value while preserving the existing external-handle path.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
game-dev
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.