Open gkvoelkl opened 4 months ago
@gkvoelkl I believe this behaves as intended.
#[derive(serde::Deserialize, Asset, TypePath)]
struct Rooms {
rooms: Vec<Room>,
}
What should the above struct serialize to as json? I'd say roughly the following:
{
"rooms": [
// the 'Room' objects here.
]
}
I am not certain about this, but I assume serde
is fine with not specifying the Rooms
object as a literal JSON object, because it only has one field. So it allows for swapping the outermost object with an array, like this:
[
[
// the 'Room' objects here.
]
]
Try putting the #[serde(transparent)]
attribute on the Rooms
struct. I think this could fix your issue.
EDIT: I haven't tested this at all, just a guess
Yeah, your .json
file is missing the rooms
field in a json object. It should work with the first example json from above.
Also, Room
is not an asset (at least not for the code you shared). It should be fine to remove the Asset
and TypePath
derives for that type.
Hello,
I try to load this JSON file:
Part of my program:
There I get the message " Failed to load asset 'cases/Mord im Herrenhaus/data/rooms.json' with asset loader 'bevy_common_assets::json::JsonAssetLoader': Could not parse the JSON: invalid type: map, expected a sequence at line 2 column 4
"
Whats wrong?
Best regards Gerhard