#bevy_proto

236 messages Β· Page 1 of 1 (latest)

left birch
#

Lemme know if you want me to edit the top post

topaz salmon
#

Sounds good. Thank you!

#

@tired ivy fyi

tired ivy
#

sweet!! thanks Alice πŸ™‚

candid elbow
#

Hi, is it possible to define bundles? Also is it possible to define prototypes for existing types like sprites and etc.?

topaz salmon
#

A prototype can contain any number of schematics which modify the world. So your schematic should be able to add whatever you want to your entity including bundles

#

For your own bundle, you can derive Schematic and set #[schematic(kind = "bundle")] on the container

#

For bevy-owned bundles, most of them exist in bevy_proto::custom. Or you can create your own schematic and set #[schematic(into = bevy::prelude::SomeBundle)]

candid elbow
#

Ha that's nice, thanks a lot. Didn't see those in the examples.

civic harbor
#

Hi !
What is the best way to add gltf assets to a prototype?
I tried bevy_proto::custom::gltf , scenesBundles (which I woul like to avoid if possible) , similarly to the SpriteBundle in the examples , with no luck.
I could implement something myself, but if a simple way already exist it would be great πŸ˜ƒ thanks in advance!

topaz salmon
#

Is there a particular schematic you're using? Generally, to load an asset you need to mark the field as #[schematic(asset)] and then in the prototype file you can do AssetPath("path/to/asset")

#

Also, I'm working on greatly improving assets for an upcoming release, just as a heads up. I'm shooting for a release by the end of the month, but we'll see (I'm currently on vacation so time to work is sparse)

civic harbor
# topaz salmon Is there a particular schematic you're using? Generally, to load an asset you ne...

Thanks for the help @topaz salmon ! I got it working after some head-scratching πŸ˜„
I am in no hurry, so very eager to see what changes you have planned for assets !
I am testing out bevy_proto to see if it can replace my very Blender/ Scene-centric workflow (components are defined as custom properties in blender and generated after loading the gltf file), love the text centric, straightforward (and commitable :D) approach of bevy_proto
Also, good vacation ! πŸ™‚

topaz salmon
#

Yeah let me know if there's anything you'd like to see! Curious to see what pain points it solves or doesn't solve compared to the Blender/Scene approach

civic harbor
#

Hi !
What is the correct way to deal with Default in the Prototypes ?
If I do not specify all fields in the Prototype ron file, I get a a call to a FromReflect method failed error, despite having a Default impl on the struct .

topaz salmon
#

You need to either mark all optional fields with #[reflect(default)] or mark the entire struct with #[reflect(Default)]

#

Note that you can also do #[reflect(default = "custom_func")] for custom default behavior or for fields that don’t impl Default

topaz salmon
tranquil cedar
#

I'm trying to figure out a way to check if a prototype is ready inside a system rather than as a run condition to a system, if there's a way in the docs I'm looking in the wrong places. Is there a way? With just basic derived schematics, if it matters.

tranquil cedar
#

ah, another look at examples/loading.rs revealed what I need. Got a bit thrown because I'm too dependant on my IDE suggestions and for some reason it's not showing any in this case, but it builds fine so..

topaz salmon
#

Which IDE? It might be because those methods are generated via macro iirc

tranquil cedar
#

VSCode with rust analyzer. It's been a bit intermittently stubborn in general lately so I'm not sure it's anything about proto in particular really

tranquil cedar
tranquil cedar
#

One proto trouble I'm getting stuck on: is there any way to get the name of a ready prototype from a handle to it so that it can be spawned, or spawn it directly through the handle?

tranquil cedar
#

In case there's another way to get there that I'm not thinking of, my objective is to load and spawn prototypes while only knowing their filenames, which may not match their internal names.

topaz salmon
#

Hm it might be a good idea to add a method on Prototypes to get that easier πŸ€”

#

I think one way to do this would be to use the handle to grab the asset directly from Res<Assets<Prototype>> and then get the name from that

tranquil cedar
#

That approach worked! thanks!

tranquil cedar
#

I attempted to follow the asset hot reload example, and got a very strange outcome... I have five prototypes in the program curently, and two of them are working perfectly. The other three don't reload. And it's not that I'm just not seeing results, I have info! statements on all the arms in the reload event system and they're just not firing for resaves of the other three files at all

#

nothing obvious to me about the files that is different, and they're all being loaded from a vec of file names. Too late at night for me to debug with any depth, but if there's any known possible gotchyas here I can check them out tomorrow

tranquil cedar
#

yeah ok, I built my project on a different computer and it's still the same ones working and not working, so I made a system that just reports on raw asset change events from the Assets<Prototype> resource and that's also not reporting any events from me saving the three non-working ones 😦

tranquil cedar
topaz salmon
#

Oh wow yeah that's a really weird issue. Glad it's getting fixed though!

tranquil cedar
#

Is it? I'd not seen any activity on it, myself. But for my immediate needs, I've switched to using load_folder anyway which dodges the issue, since unless I rename a file it should use the right case I'd imagine

topaz salmon
#

Oh whoops, I misread your message as β€œI’ll be fixing it this weekend” πŸ˜…

#

Hopefully it does actually get fixed though. Probably will come with Assets v2

tranquil cedar
#

Does there happen to be a way to make type paths in proto more permissive, or alias them so that moving things around behind the scenes dosen't have to break existing proto files?

topaz salmon
#

Permissive in what way? I think the only way to make moving files around easier is by referencing prototypes by name directly. But that means we can't automatically load those dependencies

#

(I'm assuming you're talking about templates and stuff)

tranquil cedar
#

I'm refering to the full type path being used in the autoderived schematics. So if I move a Life component from src/life.rs to src/components/mortality.rs it does something like going from MyCrate::life::Life to MyCrate::components::mortality::Life

topaz salmon
#

Oh I see

#

That's actually a Bevy issue. But should be possible now that TypePath has been released

#

And for reference, TypePath is meant to replace std::any::type_name by offering a "stable type name".

So you could do something like:

#[derive(Reflect)]
#[type_path = "my_crate::life"]
struct Life(i32);

And Life would always have the TypePath of my_crate::life::Life no matter where you move it

tranquil cedar
#

Ah. Well, I suppose I'll have to endur until then πŸ™‚

topaz salmon
#

Yeah πŸ˜…

#

Also, I realize I never left an update here. I've been really busy with life stuff so my ability to work on Bevy stuff has been significantly reduced. I'm trying to find time here and there to work on stuff, but it might be slow going for a bit :/

civic harbor
#

Is it possible to use the shortnames perhaps? (Haven't found it in the code and it does not seem work in the schematic files)
I use those in Blender_gltf_components, if there is interest I might create a PR for it ?
(Although you have to be careful with possible name collisions)

topaz salmon
#

I think I’d like to avoid short names for the time being. I had a bevy PR for type aliases that could be useful here (though, its bits are a bit rotten haha)

#

But ideally aliases would allow the user to configure their own aliases and we could have better control over collisions and even deprecation management

tranquil cedar
#

Yeah, I agree. I'm probably going to be leaving proto behind myself, not for any flaws in it but more because it was a stopgap and I've about got the gap filled properly now... for it's replacement I'm using shortname because it's easy, but I will almost certainly switch that to aliasing before too long

topaz salmon
#

Yeah and eventually it may be replaced by Bevy’s actual scenes once those are reworked (depending on if it still fills any gaps that Bevy’s scenes miss). And I think Cart’s goal is to use the shortname/aliases for schematics there as well

topaz salmon
tired ivy
#

hey, any idea why i get errors like these sometimes? It seems race-y since it happens like 20% of the time and re-running usually solves it.

2023-09-14T16:23:03.798468Z ERROR bevy_proto_backend::registration::systems: could not register prototype: the prototype with handle HandleUntyped { id: AssetPathId(AssetPathId(SourcePathId(17178281127892598469), LabelId(6298619649789039366))), handle_type: Weak } either doesn't exist or isn't fully loaded

#

I imagine im not loading something properly? this is how i load my proto files:

// in plugin impl,
app.add_system(apply_system_buffers.in_set(CustomFlush))
.add_startup_system(load_prototypes.before(CustomFlush))
//
fn load_prototypes(mut prototypes: PrototypesMut) {
        println!("Loading prototypes...");

        prototypes.load("proto/smallgreentree.prototype.ron");
        ... about 100 more files
}```
topaz salmon
#

From what I understand, Bevy doesn't guarantee assets and their dependencies are fully loaded (and inserted into the resource) by the time we get the AssetEvent::Created event. So this can cause these sorts of issues (especially with dependency assets), which is why we need Prototypes::is_ready and stuff to help minimize this problem

topaz salmon
#

I’m not sure haha I really haven’t been able to look into the new assets stuff. I believe cart mentioned that it was probably not going to be an issue after the rework though

#

Reference: #assets-dev message

tired ivy
tired ivy
topaz salmon
tired ivy
tired ivy
# topaz salmon From what I understand, Bevy doesn't guarantee assets and their dependencies are...

Hmm, i tried doing a workaround for this but im a bit confused why it didnt work.

I added a system that continuously checks if all my proto files are ready using is_ready. This system is what exists my loading state into my main game loop, so nothing should start before all proto files are ready.

However, i still run into that crazy error. I thought maybe i needed to keep trying to load the proto files too, until it worked, but that doesnt work either. (Instead of running on startup, i ran the loading system every frame in the loading state).

It seems even with repeated loading/checking if ready, it still does not work?

topaz salmon
#

Hm then it seems the error is likely originating in the prototype registry. I’m guessing that’s what actually needs to be delayed

tired ivy
#

all im doing to load my proto files is PrototypesMut::load

topaz salmon
#

No it’s built into bevy_proto_backend

#

It’s what manages and keeps track of all the prototypes

#

The registration kicks off on asset loaded, but due to the Bevy issue I mentioned earlier it’s probably trying to register while the dependencies aren’t available yet

tired ivy
#

ahh darn. so nothing i can do besides wait for 0.12, yeah?

topaz salmon
#

Hm I can try to look into. Again, it might be more effort/inefficient than it’s worth. But I’ll see what I can do!

tired ivy
wraith crow
#

How would you do a hashmap of handles with the new stuff?

#[derive(Component, Reflect, Schematic)]
#[reflect(Schematic)]
pub struct AnimationSet {
    pub animations: HashMap<String, Handle<AnimationAsset>>,
}

"lib::AnimationSet": (
            animations: {
                "idle": AssetPath("assets/player/animations/idle.prototype.ron"),
            },
        )

That's sort of what I want to write...

topaz salmon
#

Hm, that's not something built-in so you'd have to do it manually. Probably something like:

#[derive(Component, Reflect, Schematic)]
#[reflect(Schematic)]
pub struct AnimationSet {
  #[schematic(from = AssetMap)]
  pub animations: HashMap<String, Handle<AnimationAsset>>,
}

struct AssetMap(HashMap<String, ProtoAsset>);

// May need to newtype `HashMap<String, Handle<AnimationAsset>>` due to orphan rules
impl FromSchematicInput<AssetMap> for HashMap<String, Handle<AnimationAsset>> {
  fn from_input(input: AssetMap, id: SchematicId, context: &mut SchematicContext) -> Self {
    // Iterate through `input.0` and use `FromSchematicInput` to convert all the
    // `ProtoAsset` to `Handle<AnimationAsset>` values
    input.0.into_iter().map(|(key, value)| (
      key,
      FromSchematicInput::(
        value,
        id.next(Uuid::new_v4()),
        context
      )
    )).collect()
  }
}
#

Unfortunately, I don't think there's an easy way to preload those assets without manually implementing Schematic

wraith crow
#

Thanks. I don't mind implementing Schematic.

topaz salmon
#

Yeah if you do implement it manually, then you should be able to convert the ProtoAssets to Handles via FromSchematicPreloadInput in order to add them to the dependencies

wraith crow
#

Are names global? For example, if one proto has an inline child named "move_collision" and another proto has an inline child named the same thing, will that cause a collision somewhere in bevy_proto?

topaz salmon
#

Yeah currently names are global

#

One thing I want to maybe add are package specifiers, but I suppose you could just prefix the name with a package name until then

uncut finch
#

How can you load a scene asset?

(
  name: "small_box",
  schematics: {
    "bevy_proto::custom::DynamicSceneBundle": (
      scene: AssetPath("models/box-small.glb#Scene0"),
      transform: (
        translation: (
          x: -1.0,
          y: 0.5,
          z: 0.0
        )
      ),
    )
  }
)

I tried with the following, but it seems nothing gets loaded.

The path should be correct as when I spawn a SceneBundle normally, it works as expected.

#

Nevermind, just needed to replace DynamicSceneBundle with SceneBundle

rugged blade
#

how do I deal with types from other crates?

tired ivy
# rugged blade how do I deal with types from other crates?

This is what i do, using Colldier from bevy_rapier2d as an example:

#[derive(Schematic, Reflect, FromReflect)]
#[reflect(Schematic)]
#[schematic(into = Collider)]
pub struct ColliderProto {
    x: f32,
    y: f32,
}

impl From<ColliderProto> for Collider {
    fn from(col_state: ColliderProto) -> Collider {
        Collider::cuboid(col_state.x, col_state.y)
    }
}

then you just .register_type::<ColliderProto>()

rugged blade
#

for some reason I was 100% sure that I can't impl From<MyType> for ForeignType

#

this just made things a lot easier

#
error[E0119]: conflicting implementations of trait `bevy::prelude::FromReflect` for type `ColliderInput`
 --> src\proto.rs:8:30
  |
8 | #[derive(Schematic, Reflect, FromReflect)]
  |                     -------  ^^^^^^^^^^^ conflicting implementation for `ColliderInput`
  |                     |
  |                     first implementation here
  |
  = note: this error originates in the derive macro `FromReflect` (in Nightly builds, run with -Z macro-backtrace for more info)
#

apparently FromReflect is not needed anymore?

#

thanks for your help btw!

wraith crow
# topaz salmon Yeah if you do implement it manually, then you should be able to convert the Pro...
/// A dictionary of animations available to an animated entity.
#[derive(Component, Reflect, Default, Deref, DerefMut)]
#[reflect(Schematic)]
pub struct AnimationSet(pub HashMap<String, Handle<AnimationAsset>>);

#[derive(Default, Debug, Reflect)]
pub struct AnimationSetInput {
    pub animations: HashMap<String, ProtoAsset<AnimationAsset>>,
    #[reflect(ignore)]
    pub handles: HashMap<String, Handle<AnimationAsset>>,
}

impl Schematic for AnimationSet {
    type Input = AnimationSetInput;

    fn preload_dependencies(
        input: &mut Self::Input,
        id: SchematicId,
        dependencies: &mut DependenciesBuilder,
    ) {
        for (name, proto_asset) in &input.animations {
            let handle = <Handle<AnimationAsset> as FromSchematicPreloadInput<
                ProtoAsset<AnimationAsset>,
            >>::from_preload_input(
                proto_asset.clone(),
                id.next(bevy::utils::Uuid::from_u128(
                    0xB5E6A553689B43F9A6C7642CA3FC6956,
                )),
                dependencies,
            );

            input.handles.insert(name.clone(), handle);
        }
    }

    fn apply(input: &Self::Input, _id: SchematicId, context: &mut SchematicContext) {
        context
            .entity_mut()
            .unwrap()
            .insert(AnimationSet(input.handles.clone()));
    }

    fn remove(_input: &Self::Input, _id: SchematicId, context: &mut SchematicContext) {
        context.entity_mut().unwrap().remove::<AnimationSet>();
    }
}

Is what I ended up using.

topaz salmon
#

Do you run into any issues with the handles overwriting each other? Since they're all being given the same UUID for the SchematicId

#

I would have assumed you need to give them a unique value

#

Also, rather than storing a separate handles field, I think you should be able to just modify the ProtoAsset to be ProtoAsset::Handle(handle)

wraith crow
#

Let me see.

uncut finch
#

How can you modify the transform after spawning a "prefab"?

(overwriting the defined transform of the prefab file)

#

Ok I just needed to have the entity_commands() accessed from the ProtoCommands.

topaz salmon
#

Yeah that would be the way to do it (for now anyways)

uncut finch
#

Is there a simple way to add child entities, without requiring new prototypes?

For rapier physics, I often need to add multiple specific colliders to approximate the shape, but I don't need them all to be specific prototypes, bur rather just inline defined children.

topaz salmon
#

You can define children inline within a prototype

#

You can check out the hierarchy example on the repo for an example

uncut finch
#

Is there a way to define rotation in the ron files in Euler angles? (for the spatial bundle)

topaz salmon
#

Unfortunately this behavior is controlled by Quat

#

We could introduce a custom Transform input type which uses an enum to determine the rotation type (default, Euler, etc.)

#

Could you make an issue for that?

#

(you can also submit a PR for it if you want, otherwise, I'll try to get around to it for the next release)

uncut finch
#

Should it be inspired by the current godot options in the editor:

- Quaternion -> default
- XYZ Euler
- XZY Euler
- YXZ Euler
- YZX Euler
- ZXY Euler
- ZYX Euler
- Basis

Or only Quaternion and XYZ Euler ?

#

Would that mean that all the structs in the custom.rs file would then use that custom transform?

topaz salmon
#

Yeah I think we would only need the two

#

And yes, the bundles in custom.rs would use that input

#

And we could also just set the input on Transform itself to work like this

uncut finch
topaz salmon
#

What do you mean by β€œoverwrite”? Like when you spawn a prototype?

uncut finch
topaz salmon
#

Left a comment!

rugged blade
#

can I have a schematic that contains a bundle/component which contains a handle?

#

something like

struct MyBundle {
    pbr_bundle: bevy_proto::PbrBundle,
    // some other stuff
}
#

I keep getting this error: "Expected struct Handle but found AssetPath" when I don't inline the pbr bundle fields into my bundle

topaz salmon
#

I think the problem is that the bundles in bevy_proto::custom tend to use the input types directly (so ProtoAsset instead of Handle)

#

Maybe try this?

struct MyBundle {
    #[schematic(from = bevy_proto::custom::PbrBundle)]
    pbr_bundle: bevy::prelude::PbrBundle,
    // some other stuff
}
#

I honestly need to update how bundles work. I've found that they don't really nest well unfortunately

rugged blade
#

I'll just inline it

topaz salmon
#

Oh right. That’s why bevy_proto even needs to export a custom one πŸ˜…

#

Could you make an issue for this? I’d like to improve bundle usage here

rugged blade
#

I don't think I can make a proper issue since I don't quite understand how the crate works

topaz salmon
#

No worries I can try to make an issue this weekend (if life doesn’t get in the way again haha)

topaz salmon
#

FYI I'm going to merge https://github.com/MrGVSV/bevy_proto/pull/59 unless anyone has any issues with it. This PR removes the automatic forwarding of #[reflect] attributes in favor of explicit forwarding of any attribute via #[schematic_attr]. This was done to prevent certain oddities when forwarding attributes and to allow more control over the generated schematic input type

GitHub

Objective
Resolves #53
Solution
Adds the schematic_attr and asset_schematic_attr attributes to the Schematic and AssetSchematic derives, respectively. This allows attributes to be forwarded to the ...

wraith crow
#

Can ProtoCommands be used from inside Schematic::apply ?

#
    let mut system_state: SystemState<ProtoCommands> =
                SystemState::new(context.world_mut());

            let mut proto_commands = system_state.get_mut(context.world_mut());

            let body_part = proto_commands.spawn(body_part).id();

Something like this?

topaz salmon
#

I believe so πŸ€”

near bluff
#

Is it possible to add the components of two schematics together? An example of this would be if I used .insert() and both schematics has a Damage component. I'm guessing the latter insert would override the previous component. Using Bevy commands, I could do something like this to add or insert:

pub struct InsertOrAdd<T>{
    entity: Entity,
    component: T,
}

impl<T> Command for InsertOrAdd<T>
where
    T: Component + AddAssign + 'static,
{
    fn apply(self, world: &mut World) {
        if let Some(mut entity) = world.get_entity_mut(self.entity) {
            if let Some(mut component) = entity.get_mut::<T>(){
                *component += self.component;
            } else {
                entity.insert(self.component);
            }
        }
    }
}

Is it possible to do something like this in bevy_proto? Or, is there a better pattern for doing something like this?

timid sage
#

ah I see, I guess with help of this #[schematic(into = Collider)]

tired ivy
timid sage
timid sage
#

trying to run example cargo run --release --example bevy_sprite_sheet from git's main is not showing anything and throws a warning:

2023-10-09T17:10:03.088115Z  WARN bevy_asset::asset_server: encountered an error while loading an asset: RON error in "examples/bevy/sprite_sheet/Player.prototype.ron": 30:5: a call to a `FromReflect` method failed
#

can some one please help me?

topaz salmon
#

I'm able to run the example fine. Have you pulled from main recently?

topaz salmon
#

Also, I apologize for the slow progress on the crate recently. The past month and half have just been really rough irl. Hoping things get better at some point πŸ˜…

timid sage
#

@topaz salmon yes it is up to date with main it github

#
set@SET001:~/projects/bevy_proto$ git remote -v
origin    git@github.com:MrGVSV/bevy_proto.git (fetch)
origin    git@github.com:MrGVSV/bevy_proto.git (push)
set@SET001:~/projects/bevy_proto$ git branch 
* main
set@SET001:~/projects/bevy_proto$ git pull origin 
Already up to date.
set@SET001:~/projects/bevy_proto$ cargo run --package bevy_proto --example bevy_sprite_sheet --all-features
    Finished dev [unoptimized + debuginfo] target(s) in 0.15s
     Running `target/debug/examples/bevy_sprite_sheet`
2023-10-09T19:26:49.799232Z  INFO bevy_winit::system: Creating new window "App" (0v0)
2023-10-09T19:26:49.799597Z  INFO winit::platform_impl::platform::x11::window: Guessed window scale factor: 1    
2023-10-09T19:26:50.459496Z  INFO bevy_render::renderer: AdapterInfo { name: "NVIDIA GeForce GTX 1080 Ti", vendor: 4318, device: 6918, device_type: DiscreteGpu, driver: "NVIDIA", driver_info: "535.54.03", backend: Vulkan }
2023-10-09T19:26:50.663028Z  WARN bevy_asset::asset_server: encountered an error while loading an asset: RON error in "examples/bevy/sprite_sheet/Player.prototype.ron": 30:3: a call to a `FromReflect` method failed
2023-10-09T19:26:50.706037Z  INFO bevy_diagnostic::system_information_diagnostics_plugin::internal: SystemInfo { os: "Linux 21 Linux Mint", kernel: "5.15.0-53-generic", cpu: "Intel(R) Core(TM) i7-7820X CPU @ 3.60GHz", core_count: "8", memory: "31.1 GiB" }
topaz salmon
#

Interesting. What does the assets/examples/bevy/sprite_sheet/Player.prototype.ron file look like?

timid sage
#
(
  name: "Player",
  schematics: {
    "bevy_proto::custom::SpriteSheetBundle": (
      // The schematic for `TextureAtlas` defines an enum input with a `Grid` variant.
      // The fields of this variant map to the parameters of `TextureAtlas::from_grid`.
      texture_atlas: Asset(Grid(
        texture: AssetPath("textures/rpg/chars/gabe/gabe-idle-run.png"),
        tile_size: (
          x: 24.0,
          y: 24.0
        ),
        columns: 7,
        rows: 1,
        padding: None,
        offset: None,
      )),
      sprite: (
        // Start our sprite at the first frame of the run animation
        index: 1
      ),
      transform: (
        scale: (
          x: 6.0,
          y: 6.0,
          z: 6.0,
        )
      ),
    ),
    "bevy_sprite_sheet::AnimationIndices": (
      // The run animation actually starts on the second frame (index 1)
      first: 1,
      last: 6
    ),
    "bevy_sprite_sheet::AnimationTimer": ((
      duration: (
        secs: 0,
        // 1e8 nanoseconds == 0.1 seconds
        nanos: 100000000
      ),
      mode: Repeating
    ))
  }
)
topaz salmon
#

Is there a Linux feature that needs to be enabled? I'm on Mac so there's a chance I'm excluding something necessary

timid sage
#

@topaz salmon funny thing is - if I place exactly same *prototype.ron file in my project, then error would be different

2023-10-09T19:40:40.856073Z  WARN bevy_asset::asset_server: encountered an error while loading an asset: RON error in "prefabs/ship.prototype.ron": 7:27: unknown variant `Asset`, expected one of `AssetPath`, `HandleId`
topaz salmon
#

And your project is using the main branch?

#

The Asset variant is new on main (I'll put together a release sometime this week or next probably)

timid sage
#

give me a sec to switch to github in my project

#

@topaz salmon same issue when I swithing to gihtub main

a call to a `FromReflect` method failed
#

trying to test this in stand alone minimum reproducible project

topaz salmon
#

Could you do a bit of debugging there? Like, if you debug log out the reflect_input, I wonder if it's missing certain values

timid sage
#

checking...

#

@topaz salmon seems like only one of this triggered

    texture_atlas: DynamicEnum(Asset(
        DynamicEnum(Grid {
            texture: DynamicEnum(AssetPath(
                "textures/rpg/chars/gabe/gabe-idle-run.png",
            )),
            tile_size: DynamicStruct(glam::f32::vec2::Vec2 {
                x: 24.0,
                y: 24.0,
            }),
            columns: 7,
            rows: 1,
            padding: DynamicEnum(None),
            offset: DynamicEnum(None),
        }),
    )),
    sprite: DynamicStruct(bevy_proto_backend::impls::bevy_impls::sprite::TextureAtlasSpriteInput {
        index: 1,
    }),
    transform: DynamicStruct(bevy_transform::components::transform::Transform {
        scale: DynamicStruct(glam::f32::vec3::Vec3 {
            x: 6.0,
            y: 6.0,
            z: 6.0,
        }),
    }),
})
2023-10-09T20:12:50.112817Z  WARN bevy_asset::asset_server: encountered an error while loading an asset: RON error in "examples/bevy/sprite_sheet/Player.prototype.ron": 30:5: a call to a `FromReflect` method failed
#

updated to pretty print )

topaz salmon
#

Hm, so the issue is with the SpriteSheetBundle schematic and not the AnimationIndices or AnimationTimer schematics

#

Honestly, that all looks right to me πŸ˜…

timid sage
#

with SpriteSheetBundleInput, not the SpriteSheetBundle, right?

#

I can't even find this struct in repo *(

#

I guess it is generated with macro?

topaz salmon
#

Yeah with the input

#

And yes, it's generated by the derive macro

timid sage
#

strange that you can't reproduce it. this might mean something specific on my side

#

but I can't image what and how to debug *(

topaz salmon
#

Yeah I’m at a complete loss myself haha

#

Maybe someone else running a Linux can test? That’s the only thing I can think of

timid sage
topaz salmon
#

Should be in src/custom.rs

timid sage
#

I can also try to run it in doker with clean linux or maos and see how it go there *(

high onyx
#

Is there a way to spawn multiple entities out of 1 proto file?

I am defining items that all look very similar in terms of their definitions, and want to spawn them with a single call and define them all alongside eachother ideally in one file rather than creating lots of tiny files and loading them all individually. Is this workflow supported?

For example in bevys current scene implementation its possible to spawn multiple entities relatively easily https://github.com/bevyengine/bevy/blob/e5f5ce5e9738983a1d4e46b864d2714b638e747e/assets/scenes/load_scene_example.scn.ron#L4

GitHub

A refreshingly simple data-driven game engine built in Rust - bevyengine/bevy

topaz salmon
#

One hack for doing that would be to create a β€œparent” proto file. Then in that file, reference your other proto as children of that parent. You can then create as many duplicates as you want

#

Obviously not ideal haha but works if you don’t want to create a custom schematic for duplicating the entity

high onyx
#

yeah I thought about that as an option, not my first choice but might be the best option right now

topaz salmon
#

Yeah one of the things I was working on was prototype parameters which could possibly be used to achieve this

near bluff
# topaz salmon You'd have to manually implement `Schematic` to do something like this. I'm not ...

No worries, hope things get better soon! Thank you for the help and the crate! I think this might work (I haven't tested it yet). The good thing actually about impl Schematic instead of a custom Command is that some types can be a multiplier instead of adding if I need it to.

impl Schematic for Damage{
    type Input = Self;
    fn apply(input: &Self::Input, context: &mut SchematicContext) {
        let mut entity = context.entity_mut().unwrap();

        if let Some(mut component) = entity.get_mut::<Damage>(){
            component.0 += input.0;
        } else {
            entity.insert(*input);
        }
    }

    fn remove(_input: &Self::Input, context: &mut SchematicContext) {
        context.entity_mut().unwrap().remove::<Damage>();
    }
}
timid sage
#

@topaz salmon I have checked that issue on another linux machine and still have same behavior there. Both time using rustc 1.73.0 (cc66ad468 2023-10-03)

#

can some one with linux machine place try to check bevy-proto bevy examples?

timid sage
#

how to set texture_atlas for evy_proto::custom::SpriteSheetBundle in 0.11.0? curently I can only set it with AssetPath but not with Grid

#

also even it does not throw any errors, spritesheet is not whown up *(

hot dirge
#

First of all: Thanks for the great work on bevy_proto! πŸ™‚
I have an issue running the asset_loading example of the current main branch.
This is from a fresh clone of the repo:

2023-10-14T09:25:28.488003Z  INFO bevy_diagnostic::system_information_diagnostics_plugin::internal: SystemInfo { os: "MacOS 14.0 ", kernel: "23.0.0", cpu: "Apple M1", core_count: "8", memory: "16.0 GiB" }
2023-10-14T09:25:28.492472Z  WARN bevy_asset::asset_server: encountered an error while loading an asset: RON error in "examples/bevy/asset_loading/Monkey.prototype.ron": 22:3: a call to a `FromReflect` method failed
2023-10-14T09:25:28.492480Z  WARN bevy_asset::asset_server: encountered an error while loading an asset: RON error in "examples/bevy/asset_loading/Sphere.prototype.ron": 28:3: a call to a `FromReflect` method failed
2023-10-14T09:25:28.494608Z  WARN bevy_asset::asset_server: encountered an error while loading an asset: RON error in "examples/bevy/asset_loading/Cube.prototype.ron": 28:3: a call to a `FromReflect` method failed

Let me know if you need more information or if I can help in any way. Would be great for my game to get this working πŸ™‚

timid sage
#

@hot dirge having same issue here on Linux

topaz salmon
#

Hey all! Sorry I haven't been very responsive lately. My wife is dealing with some health issues so my time/motivation to do library work is pretty minimal at the moment haha. Feel free to continue making issues and PRs or posting here. I'll try to review or respond as fast as I can, but I can't really guarantee that I'll be pushing much code myself aside for maybe releases

hot dirge
timid sage
#

@topaz salmon all the best to your wife and thank you for this cool crate

obsidian mountain
#

Hope things are improving with your wife's health MrGVSV.
Anyone know what the best way is to iterate over all the loaded prototypes?

topaz salmon
#

Thank you! She’s doing a lot better. Now it’s our preterm infant that we gotta worry about πŸ˜…

obsidian mountain
#

Ahh excellent πŸ‘Œ thanks.
Congrats on the new addition to the family 😁

topaz salmon
#

Hey everyone! I'm starting to get into a NICU rhythm haha so I might have time to get around to updating the crate for 0.12 soon!

#

Although I am afraid of how much I may need to change due to the Assets v2 😬

topaz salmon
#

I'm hopeful Assets v2 will fix a lot of things and improve certain areas of the crate. However, to fully make use of these features, I might decide to refactor a lot more than putting out a simple 1-to-1 update. I'll explore it a bit and see what needs to be done!

#

For example, we may want to make use of asset preprocessing, loader settings, etc.

#

Which is all stuff I sorta emulated via the Config and Loader traits. So we may be able to offload more of that stuff back onto Bevy

near bluff
tired ivy
#

Hey, happy holidays! Just wanted to check in, if theres something I can do to help with getting this to bevy 0.12 πŸ™‚

topaz salmon
#

Hey @tired ivy! Unfortunately I think the only way this crate is getting updated to 0.12 is if someone submits a PR πŸ˜…. My son is still in the NICU so a large refactoring project has not been something I’m prepared to take on haha

#

If things start going well here and I feel extra motivated, I might pick it back up. But I can’t make any promises as of yet

#

(The BSN work also is a small hit to motivation since it would likely replace the need for this crate haha)

tired ivy
#

I havent fully read up on the 0.12 changes, what is BSN? (the thought of reworking my 100+ proto files is bringing pain to my brain rn haha)

topaz salmon
#

Lol no worries

#

It’s not in 0.12, but I think the devs want to merge it into 0.13 (0.14 at the latest)

#

I’ll find the discussion

#

It’s a whole new scene format that will work in both an asset file and an inlinable macro invocation

#

I’m pretty excited for it honestly. Once it’s in, I’m not sure if bevy_proto will be offering much more beyond templates (maybe asset schematics but we’ll see how BSN evolves)

#

There’s been some recent discussion here: #scenes-dev message

topaz salmon
#

The actual AssetLoader stuff isn’t all too different based on the little I did manage to get done with the upgrade

#

Like, I don’t think we need to include any additional asset processing since prototypes are technically supposed to work via code as well so processing might actually create an unwanted split between the asset and code-based prototypes

tired ivy
#

i just did a read through of the proposal, and it seems super exciting! Very not looking forward to refactoring everything but this is certainly the right direction to go in.

#

ill give updating to 0.12 a shot, since i wont be able to continue working on my game without it i think. (although maybe ill just stay on 0.10.x)

#

is any work you've done just been merged to master ,or is there a branch?

topaz salmon
#

I have a local branch but it really isn't much. I think I got stuck on the asset stuff pretty much at the start lol

tired ivy
#

ok fair enoguh, ill start fresh! ill know this week if its something im capable of doing or not πŸ™‚

tired ivy
#

Hey, any idea why bevy_proto v0.10.0 is seemingly using bevy v0.12.1 as a dependancy? doing cargo tree gives me this:

── bevy_proto v0.10.0
β”‚   β”œβ”€β”€ anyhow v1.0.76
β”‚   β”œβ”€β”€ bevy v0.12.1
β”‚   β”‚   └── bevy_internal v0.12.1
β”‚   β”‚       β”œβ”€β”€ bevy_a11y v0.12.1
β”‚   β”‚       β”‚   β”œβ”€β”€ accesskit v0.12.1
β”‚   β”‚       β”‚   β”œβ”€β”€ bevy_app v0.12.1
β”‚   β”‚       β”‚   β”‚   β”œβ”€β”€ bevy_derive v0.12.1 (proc-macro)
β”‚   β”‚       β”‚   β”‚   β”‚   β”œβ”€β”€ bevy_macro_utils v0.12.1
β”‚   β”‚       β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ proc-macro2 v1.0.71 (*)
β”‚   β”‚       β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ quote v1.0.33 (*)
β”‚   β”‚       β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ rustc-hash v1.1.0
β”‚   β”‚       β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ syn v2.0.42 (*)
β”‚   β”‚       β”‚   β”‚   β”‚   β”‚   └── toml_edit v0.20.7
β”‚   β”‚       β”‚   β”‚   β”‚   β”‚       β”œβ”€β”€ indexmap v2.1.0 (*)
β”‚   β”‚       β”‚   β”‚   β”‚   β”‚       β”œβ”€β”€ toml_datetime v0.6.5
...``` 

I see this inside the crate cargo toml that is auto-downloaded, could this be the issue?
```[dependencies.bevy]
version = ">=0.10.1"
features = ["bevy_asset"]
default-features = false```
#

it seems that its causing my v0.10 bevy app to no longer compile, with this error (which from searching in this discord, is from bevy version miss-matches)

error[E0063]: missing fields `grid_auto_columns`, `grid_auto_flow`, `grid_auto_rows` and 5 other fields in initializer of `taffy::prelude::Style` --> /Users/ramin/.cargo/registry/src/index.crates.io-6f17d22bba15001f/bevy_ui-0.10.1/src/flex/convert.rs:99:5 | 99 | taffy::style::Style { | ^^^^^^^^^^^^^^^^^^^ missing `grid_auto_columns`, `grid_auto_flow`, `grid_auto_rows` and 5 other fields

#

Ok, nvm all that. I did a bunch of stuff and the issue went away. I did a bunch of variations of cargo clean, cargo update, and cargo build, as well as removing/adding the bevy_proto dependancy.

topaz salmon
#

Weird. Yeah probably an issue with the cargo registry not cleaning itself out properly

near bluff
#

I was looking through the code but couldn't find the answer, is it possible to get the components and its values of a loaded prototype using an Id?

For context, in the spell system I'm working on, a Spell has a String field to its prototype and I am trying to print the components with their value on the prototype onto a console.

#

It looks it might be able to be done using ProtoRegistry<T: Prototypical, C: Config<T>>, but idk for sure?

topaz salmon
#

I don’t think the registry is public

#

I could have sworn there was a way to get a prototype handle by name, but it doesn’t look like there’s a way to do that via the Prototypes system param

near bluff
#

So, I ended up forking bevy_proto to make ProtoRegistry public (don't know if this is the only way) and so far it's going good. I can get the name of each relevant schematic but the only issue I'm having right now is getting the value. I'm still inexperienced with reflect so getting the value is probably not how I'm going about it. Right now I'm getting the field of the schematic and then trying to get the data from AppTypeRegistry.

let prototype_id = proto_registry.get_tree_by_id(spell.0.schematic.clone()).unwrap().handle();
let handle = prototypes.get_handle(prototype_id);
let prototype = prototypes.get(&handle).unwrap();
for (path, schematic) in prototype.schematics().iter() {
    let Some(name) = path.split("::").nth(3) else {
        continue;
    };
    let value = match schematic.type_info() {
        TypeInfo::Struct(info) => {
            let Some(field) = info.field_at(0) else {
                continue;
            };
            match field.type_name() {
                //                                                                   This unwrap panics
                "u32" => registry.read().get(field.type_id()).unwrap().data::<u32>().unwrap().to_string(),
                //"i32" => schematic.input().downcast_ref::<i32>().unwrap().to_string(),
                //"f32" => schematic.input().downcast_ref::<f32>().unwrap().to_string(),
                _ => continue,
            }
        },
        _ => continue,
    };
    print!("{}: {}    ", name, value);
}
#

When checking the short_name() of the type_id() from the registry is prints out u32

#

I wonder, is there a way to print out the field's value without needing to know the type itself?

topaz salmon
#

What data are you trying to get? u32 isn't valid type data. Maybe you meant to get the field through Struct::field?

near bluff
# topaz salmon What data are you trying to get? `u32` isn't valid type data. Maybe you meant to...

That was exactly it! Filtered out SceneBundle as it's not needed information. Thank you for the help, it's very much appreciated! πŸ™‚

Terminal Output:

====================================
Inventory Stats
----------------
Total Cast Delay: 0    Total Reload Delay: 0

Homing Orb Stats
----------------
Type: Projectile    Cast Delay: +2    Reload Delay: +0    Mana: 35
Damage: 3    Lifetime: 12    Speed: 1    // <------ (Prototype Information)
====================================
Incoming Enemies
----------------
droid x7
scout x33

Code:

for (_, schematic) in prototype.schematics().iter() {
        let ReflectRef::Struct(component) = schematic.input().reflect_ref() else {
            continue;
        };

        let name = component.reflect_short_type_path();
        if name.contains("SceneBundleInput") {
            continue;
        }
        
        let Some(field) = component.field_at(0) else {
            continue;
        };

        print!("{}: {:?}    ", name, field);
    }