MrGVSV / bevy_proto

Create config files for entities in Bevy
Other
239 stars 25 forks source link

String Vector schematic #48

Closed hafiidz closed 1 year ago

hafiidz commented 1 year ago

I am trying to create a schematic that is able to read the prototype.ron files that contains vector/arrays of String, pseudocode below"

// in schematic.rs 
#[derive(Component, Default, Reflect, Debug, Clone)]
#[reflect(Schematic)]
pub struct Cardset {
    pub on_game: Vec<String>,
    pub on_deck: Vec<String>,
    pub on_hand: Vec<String>,
}

//ron file 
(
  name: "CardsetRoot",
  schematics: {
    "deck_proto::app::schematic::Cardset": (
        on_game: [],
        on_deck: [],
        on_hand: ["Card1", "Card2"],
   ),
  },
)

Tried a few different variation but often encountered errors, such as

WARN bevy_asset::asset_server: encountered an error while loading an asset: RON error in "schematics/cardset/CardsetRoot.prototype.ron": 5:14: no registration found for type alloc::vec::Vec<alloc::string::String>

Appreciate some advice on the right direction I need to explore further ya. Not sure where to refer.

MrGVSV commented 1 year ago

Try adding .register_type::<Vec<String>>() to your App. Most of the time, a no registration found for type error can be resolved like that.

Due to the fact that type registrations need to be manually monomorphized, Bevy simply opts not to register too many generic types itself. Instead, it relies on the user to register the ones they need. Eventually, this won't be as big an issue when https://github.com/bevyengine/bevy/pull/5781 lands.


Also as a side note, you can add #[reflect(default)] to your fields to avoid having to define empty arrays in your RON file. You may already know that haha but just wanted to give that tip just in case you didn't.

hafiidz commented 1 year ago

Awesome, that helps greatly. Both the register_type and #[reflect(default)] advise is super helpful. Manage to get things working now. Totally forget about the default features, hehehe.