https://github.com/MrGVSV/bevy_proto by @topaz salmon
Create config files for entities in Bevy
236 messages Β· Page 1 of 1 (latest)
https://github.com/MrGVSV/bevy_proto by @topaz salmon
Create config files for entities in Bevy
Lemme know if you want me to edit the top post
sweet!! thanks Alice π
Hi, is it possible to define bundles? Also is it possible to define prototypes for existing types like sprites and etc.?
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)]
Ha that's nice, thanks a lot. Didn't see those in the examples.
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!
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)
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 ! π
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
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 .
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
Decided to create a tracking issue for my asset work. This is just meant to let people know that I'm actively working on this feature.
https://github.com/MrGVSV/bevy_proto/issues/47
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.
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..
Which IDE? It might be because those methods are generated via macro iirc
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
I've actually posted a skeleton of my project using _proto over in code review https://discord.com/channels/691052431525675048/1138127782652674179, I don't have any problems with proto in it that I know of, but seemed worth dropping a mention in case there's any problems I don't know of π
Discord is the easiest way to communicate over voice, video, and text. Chat, hang out, and stay close with your friends and communities.
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?
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.
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
That approach worked! thanks!
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
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 π¦
~~Wasn't sure if my issue is proto or just asset related so I made a main help thread about it, haven't gotten answers but I do have a very stripped down repro package there now https://discord.com/channels/691052431525675048/1139612446936539136 ~~
Edit: Looks like it's a bevy issue that I'll be filing this weekend
Oh wow yeah that's a really weird issue. Glad it's getting fixed though!
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
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
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?
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)
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
Oh I see
That's actually a Bevy issue. But should be possible now that TypePath has been released
Actually, I think we still need https://github.com/bevyengine/bevy/pull/8768
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
Ah. Well, I suppose I'll have to endur until then π
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 :/
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)
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
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
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
Btw, I should be merging https://github.com/MrGVSV/bevy_proto/pull/57 sometime tomorrow. This PR adds AssetSchematic to allow for inlinable assets!
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
}```
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
Is this still true on main?
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
ah so i need to check every time with is_ready? or at least in systems that run on startup? I seem to get these 80% of the time now. I have to restart my game multiple times until it works once. I think the more proto file loading i added the worse its got
ah if it will get fixed on 0.12 then im okay waiting. Im still on 0.10.1 anyway
Yeah and even that is susceptible. We could add some complexity to get it working (recursive checks, etc.) but Iβd rather just wait for 0.12 haha
yeah agreed, not worth the work right now π
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?
Hm then it seems the error is likely originating in the prototype registry. Iβm guessing thatβs what actually needs to be delayed
hmm, what exactly is that, is that something i can delay on my end?
all im doing to load my proto files is PrototypesMut::load
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
ahh darn. so nothing i can do besides wait for 0.12, yeah?
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!
ah no worries, dont stress on it too much π
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...
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
Thanks. I don't mind implementing Schematic.
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
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?
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
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
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>()
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!
/// 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.
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)
Let me see.
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.
Yeah that would be the way to do it (for now anyways)
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.
You can define children inline within a prototype
You can check out the hierarchy example on the repo for an example
Is there a way to define rotation in the ron files in Euler angles? (for the spatial bundle)
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)
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?
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
Its possible to overwrite how something is used inside of a bundle? (like spatial bundle)
Is there an example how to achieve this?
What do you mean by βoverwriteβ? Like when you spawn a prototype?
Created the issue: https://github.com/MrGVSV/bevy_proto/issues/61
Is that how you had in mind it could be implemented?
Left a comment!
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
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
bevy's pbr bundle doesn't implement reflect
I'll just inline it
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
I don't think I can make a proper issue since I don't quite understand how the crate works
No worries I can try to make an issue this weekend (if life doesnβt get in the way again haha)
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
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?
I believe so π€
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?
so in ron file you use ColliderProto, right? and then how do you get Collider finally in entity?
ah I see, I guess with help of this #[schematic(into = Collider)]
yup, it converts it, its like an alias, you can pass arbitrary data and construct any bundles or components ytou want to add
yeah, this works. It requires some additional work, though
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
also, when I'm trying to use ron from example ( https://github.com/MrGVSV/bevy_proto/blob/main/assets/examples/bevy/sprite_sheet/Player.prototype.ron#L4-L29 ) in my project the error is different:
2023-10-09T16:49:31.844659Z WARN bevy_asset::asset_server: encountered an error while loading an asset: RON error in "prefabs/ship.prototype.ron": 23:27: unknown variant `Asset`, expected one of `AssetPath`, `HandleId`
can some one please help me?
I'm able to run the example fine. Have you pulled from main recently?
You'd have to manually implement Schematic to do something like this. I'm not sure how we'd generalize that kind of behavior via the derive macro
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 π
@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" }
Interesting. What does the assets/examples/bevy/sprite_sheet/Player.prototype.ron file look like?
just the same as in repo
(
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
))
}
)
Is there a Linux feature that needs to be enabled? I'm on Mac so there's a chance I'm excluding something necessary
don't know any such special feature
@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`
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)
main is using crates.io
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
There are only two places this error shows up:
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
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 )
Hm, so the issue is with the SpriteSheetBundle schematic and not the AnimationIndices or AnimationTimer schematics
Honestly, that all looks right to me π
with SpriteSheetBundleInput, not the SpriteSheetBundle, right?
I can't even find this struct in repo *(
I guess it is generated with macro?
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 *(
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
where I can found it in code? I never had a deal with macros but maybe I will be able to debug it somehow * (
Should be in src/custom.rs
I can also try to run it in doker with clean linux or maos and see how it go there *(
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
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
yeah I thought about that as an option, not my first choice but might be the best option right now
Yeah one of the things I was working on was prototype parameters which could possibly be used to achieve this
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>();
}
}
@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?
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 *(
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 π
@hot dirge having same issue here on Linux
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
No worries, thanks for the heads-up! Will try to look into the issue myself if I find time. All the best for your wife. π
@topaz salmon all the best to your wife and thank you for this cool crate
Hope things are improving with your wife's health MrGVSV.
Anyone know what the best way is to iterate over all the loaded prototypes?
Thank you! Sheβs doing a lot better. Now itβs our preterm infant that we gotta worry about π
As far as iterating over all prototypes, theyβre stored as assets. So I believe you can use something like https://docs.rs/bevy/latest/bevy/asset/struct.Assets.html#method.iter
Stores Assets of a given type and tracks changes to them.
Ahh excellent π thanks.
Congrats on the new addition to the family π
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 π¬
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
I found the commit that causes the a call to a FromReflect method failederror, which is the latest commit: a6e9509. After looking through the commit, I don't know what specifically is causing the error though, sorry. Hope this information is helpful and if there is anything you'd like me to test, let me know. π
Hey, happy holidays! Just wanted to check in, if theres something I can do to help with getting this to bevy 0.12 π
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)
oh crap i did not read further up, i thought this message was a typo meant to be NICE. I hope everything goes well with your newborn, wishing you all good health β€οΈ
definitely don't worry about this, ill see if Its something im capable of doing, i'd love to help.
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)
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
If you (or anyone else) does decide to tackle the update to 0.12, donβt be afraid to come to me with questions. I think the biggest breakage is the AssetSchematic stuff since 0.12 really changed how we interact with assets (specifically setting an asset and getting a strong handle to it from just a HandleId)
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
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?
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
ok fair enoguh, ill start fresh! ill know this week if its something im capable of doing or not π
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.
Weird. Yeah probably an issue with the cargo registry not cleaning itself out properly
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?
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
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?
What data are you trying to get? u32 isn't valid type data. Maybe you meant to get the field through Struct::field?
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);
}