bevyengine / bevyengine/bevy

Make Handle to be a Component (again)

Open
#19,407 4 comments 1 reaction 0 assignees View on GitHub
A-Assets C-Feature S-Needs-Design X-Needs-SME
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?

A Handle is needed to access loaded objects of specific type for example gltf:
let handle: Handle = asset_server.load("Fox.glb");
Later you could access the Gltf content by query with specific marker set during spawn.
However, Handle "was removed from being Component because it is an anti-pattern".

### Note.
Accessing to loaded mesh or texture with changing it on run time is the basic and commonly used feature in game engine. In Bevy, such access is made by Handle. What and why exactly do you see in Handle being Component as "anti pattern" ?

### First
Such "removal of anti pattern" do not work, because user may just inbox his own component:
#[derive(Resource)]
struct GltfHandle(Handle);
and put into bundle, so you can not "force" the user to avoid the "anti-pattern", if user wants to work that way.

### Second.
In other exampes where you query like for Mesh3d, Meshmaterial3d with the same function, so again it is not understandable what makes this use case actually an anti pattern, but it seems not be possible with gltf data, cause seems like SceneRoot does not allow to get references to content inside of the glb.

(maybe you can save you work and make framework clear without introducing unnecessary inboxing types of Handle but i would not discuss it here)

## What alternative(s) have you considered?

The standart Bevy examples like
https://bevyengine.org/examples/3d-rendering/query-gltf-primitives/
do not actually show query for specific mesh material inside of gltf. Furthermore, this is actually a "bad example".

```
mat_query: Query<(
&MeshMaterial3d,
&Mesh3d,
&GltfMaterialName,
)>,
```
you just query for all materials with given name .
```
for (mat_handle, mesh_handle, name) in mat_query.iter() {
// locate a material by material name
if name.0 == "Top" {
```
then, you select one material by its name, what is wrong, since :
### selecting components, what should be processed should happen in query, usually by marker set to the bundle and not in loop and if check, this IS actually an anti pattern in ECS.
### this would not work in real game example anyway , where multiple glb files are loaded what can have different materials with same name unique only per each glb file.

## What solution would you like?

As i wrote, make Handle to be a Component (again), and do not deside what is anti pattern and what is not for people who actually make games and may know better what API they want.

Contributor guide

Open the contributing guide

Research direction

Start with the `query-gltf-primitives` example and the Handle and SceneRoot behavior described in the issue; compare querying named glTF materials with marker-based selection. Done requires a maintainer decision on whether Handle should again be a Component and a concrete API or example path for accessing specific loaded glTF content.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
game-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.