Skip to content

Users must specify storage type for Component when used as a trait object #3265

Closed
@alice-i-cecile

Description

@alice-i-cecile

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

When attempting to create a trait object of a Component, users must specify the storage type as either Component<Storage=TableStorage> or Component<Storage=SparseStorage>.

Reproduction:

use bevy::prelude::*;

fn main() {
    let boxed_component: Box<dyn Component> = Box::new(Transform::identity());
}

If they do not do so, they receive a compiler error like:

the value of the associated type `Storage` (from trait `bevy::prelude::Component`) must be specified

This is both somewhat confusing to resolve and frustratingly limiting, as you cannot mix and match storage types within types that you intend to store in the same trait object.

What solution would you like?

Somehow refactor the way storage types are recorded (see bevyengine/rfcs#27 for alternate approaches) to avoid this limitation.

Additional context

Encountered when exploring topics related to #3227.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ECSEntities, components, systems, and eventsC-BugAn unexpected or incorrect behaviorC-UsabilityA targeted quality-of-life change that makes Bevy easier to use

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions