MrGVSV / bevy_proto

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

Insert prototype data on existing entities #10

Closed MrGVSV closed 2 years ago

MrGVSV commented 2 years ago

Objective

Add ability to insert prototype data on existing entities.

Solution

Added default trait method to Prototypical called insert, which takes an EntityCommands object. Its usage looks something like:


fn attach_components(entity: &mut EntityCommands, data: &ProtoData, asset_server: &AssetServer) {
  let proto = data.get_prototype("My Prototype").expect("Should exist!");
  proto.insert(entity, data, asset_server).insert(SomeOtherComponent);
}