Skip to content

deserialize a ron file to an asset in AssetServer#1673

Closed
mockersf wants to merge 1 commit intobevyengine:mainfrom
mockersf:ron-deserialization
Closed

deserialize a ron file to an asset in AssetServer#1673
mockersf wants to merge 1 commit intobevyengine:mainfrom
mockersf:ron-deserialization

Conversation

@mockersf
Copy link
Member

@mockersf mockersf commented Mar 17, 2021

this PR makes it very easy to deserialise any struct as an asset from a ron file:

  1. declare your asset
#[derive(Debug, Deserialize, TypeUuid)]
#[uuid = "abfa1180-abfa-41fa-80a1-2af49dd778fd"]
pub struct Character {
    name: String,
    hit_points: u32,
}
  1. register it
app.add_asset::<Character>();
  1. load it 🎉
let character: Handle<Character> = asset_server.deserialize("data/character.ron");

It depends on #1665 to work, and won't build without.

@alice-i-cecile alice-i-cecile added A-Assets Load files from disk to use for things like images, models, and sounds C-Feature A new feature, making something new possible labels Mar 17, 2021
Copy link
Member

@alec-deason alec-deason left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would replace uglier custom code in my project, that's nice.

}

impl RonAssetDeserializer for AssetServer {
fn deserialize<T: for<'de> Deserialize<'de> + Asset>(&self, path: &str) -> Handle<T> {
Copy link
Contributor

@huhlig huhlig Apr 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should likely be named something akin to load_ron to match the other load methods.

@mockersf mockersf marked this pull request as draft April 23, 2021 21:37
@cart cart added the S-Pre-Relicense This PR was made before Bevy added the Apache license. Cannot be merged or used for other work label Jul 23, 2021
@mockersf mockersf removed the S-Pre-Relicense This PR was made before Bevy added the Apache license. Cannot be merged or used for other work label Jul 24, 2021
@mockersf
Copy link
Member Author

mockersf commented Jun 1, 2022

closing with #1665

@mockersf mockersf closed this Jun 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Assets Load files from disk to use for things like images, models, and sounds C-Feature A new feature, making something new possible

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants