Default Mesh3d with Bevy 0.15 require
components
#18946
Unanswered
TanJunKiat
asked this question in
Q&A
Replies: 1 comment
-
While you can't access the #[derive(Component)]
#[require(Transform, MeshMaterial3d<StandardMaterial>)]
#[component(on_add = add_default_cube)]
struct CustomComponent;
pub fn add_default_cube(mut world: DeferredWorld<'_>, HookContext { entity, .. }: HookContext) {
// Retrieve a mesh handle. This handle could also be retrieved from a Resource instead of created here
let Some(mut meshes) = world.get_resource_mut::<Assets<Mesh>>() else {
return;
};
let mesh_handle = meshes.add(Cuboid::from_length(1.));
// Add the component
world.commands().entity(entity).insert(Mesh3d(mesh_handle));
} Now simply spawning cmd.spawn(CustomComponent); I added |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
The new
require
components is really helpful to simplify the components required to define for a bundle and/or entity.I want to create an entity where it has a default
Mesh3d
of a 1 meter cube and using the scale attribute inTransform
to resize it, because it is easier to query and recover the size in other systems.Right now, I am struggling to define a
Default
trait for my meshWhat i am familiar with is using the assets server to spawn meshes. Not sure how should I go about doing this.
Beta Was this translation helpful? Give feedback.
All reactions