Skip to content

API inconsistency with Handle as component or field of component #14124

@benfrankel

Description

@benfrankel

Question

Should components with associated assets (e.g. Sprite + Handle<Image>) include their Handle as a field, or as a separate component on the same entity, or something else?

  • Handle-as-field: May make certain generic systems impossible (see the asset_decompression example).
  • Handle-as-component: May create ambiguity (see EnvironmentMapLight).

From the Discord discussion, this is blocked on Bevy scenes before a design decision can be made.

Status quo

Bevy's answer to this question is inconsistent (as of March 6th, 2024):

Component with a wrapped Handle field:

  • UiImage::texture: Handle<Image>
  • TextureAtlas::layout: Handle<TextureAtlasLayout>
  • Skybox::image: Handle<Image>
  • Mesh2dHandle::0: Handle<Mesh>
  • SkinnedMesh::inverse_bindposes: Handle<SkinnedMeshInverseBindposes>
  • Lightmap::image: Handle<Image>
  • IrradianceVolume::voxels: Handle<Image>
  • EnvironmentMapLight::diffuse_map: Handle<Image>
  • EnvironmentMapLight::specular_map: Handle<Image>

Component with an associated Handle-as-component:

  • Sprite + Handle<Image>
  • more? hard to ripgrep for this

Bundle with a Handle-as-component field:

  • SpriteBundle::texture: Handle<Image>
  • SceneBundle::scene: Handle<Scene>
  • DynamicSceneBundle::scene: Handle<DynamicScene>
  • MaterialMesh2dBundle<M>::material: Handle<M>
  • MaterialMeshBundle<M>::material: Handle<M>
  • MaterialMeshBundle<M>::mesh: Handle<Mesh>
  • MaterialNodeBundle<M>::material: Handle<M>
  • AudioSourceBundle<Source>::source: Handle<Source>

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-AssetsLoad files from disk to use for things like images, models, and soundsA-Cross-CuttingImpacts the entire engineA-ScenesComposing and serializing ECS objectsC-UsabilityA targeted quality-of-life change that makes Bevy easier to useS-Waiting-on-SMEThis is currently waiting for an SME to resolve something controversialX-BlessedHas a large architectural impact or tradeoffs, but the design has been endorsed by decision makers

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions