Skip to content

Meta-issue for improving reflect-deserialized asset loading #15518

@aecsocket

Description

@aecsocket

This is a meta-issue for tracking the progress of improving how reflect-deserialized assets get loaded. This is a cross-cutting concern between both reflection and assets.

The motivating use case comes from bevy_animation_graph, where we deserialize AnimationGraphs from RON files. This looks like:

#[derive(Asset, Reflect)]
struct AnimationGraph {
    pub nodes: Vec<AnimationNode>,
    pub edges: (...),
}

#[derive(Reflect)]
struct AnimationNode {
    pub name: String,
    pub inner: Box<dyn NodeLike>, // NodeLike: Reflect
}

#[derive(Reflect)]
#[reflect(NodeLike)]
struct AnimationClipNode {
    pub clip: Handle<AnimationClip>,
}

#[derive(Reflect)]
#[reflect(NodeLike)]
struct ChangeSpeedNode;

(
    nodes: [
        (
            name: "Walk clip",
            ty: "bevy_animation_graph::node::AnimationClipNode",
            inner: (
                clip: "animation_clips/walk.animclip.ron",
            )
        ),
        (
            name: "Change speed",
            ty: "bevy_animation_graph::node::ChangeSpeedNode",
            inner: (),
        ),
    ],
    edges: ( ... ),
)

The two important things here are:

  • AnimationNode stores a type-erased NodeLike
  • AnimationClipNode, and other node types, may store asset handles

However, it's currently very annoying to write code to deserialize and load this asset properly. Why?

If these issues are solved, we have a much more powerful way to easily define these kinds of complex assets which depend on other assets, and that also use reflection to deserialize values of unknown types.

Once these are resolved, I would like to write an example which deserializes an asset in this reflective way, showing off the automatic recursive Handle loading, and deserializing type-erased Box<dyn Reflect>s.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-AssetsLoad files from disk to use for things like images, models, and soundsA-ReflectionRuntime information about typesC-Tracking-IssueAn issue that collects information about a broad development initiativeS-Ready-For-ImplementationThis issue is ready for an implementation PR. Go for it!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions