-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Guard against VisibilityClass being duplicated while cloning #21069
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Guard against VisibilityClass being duplicated while cloning #21069
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we leave a quick note in the doc comments about this behavior and why it exists? Other than that, I like this solution much better!
The test I provided on the previous pull request is still relevant to test cloning does not introduce duplicates and cloning still adds a visibility class. |
I'll see about adding it back in |
f976d48
to
b336acb
Compare
@dloukadakis I added your test back in and @alice-i-cecile I added some documentation. Let me know if there is anything else I can do to get this across the finish line. Thanks! |
Co-authored-by: Dimitrios Loukadakis <[email protected]>
b336acb
to
9f5345f
Compare
@dloukadakis @tychedelia @eugineerd, want to give this a look? This needs two approvals to be merged. |
# Objective - This is the second attempt at "Fixes #20884" after conversation in #20891 ## Solution - I followed the approach discussed in #20891 to add `#[component(clone_behavior=Ignore)]` to avoid cloning this Component ## Testing - I tested the change with a simple repro. I'm not sure if I can unit test just the existence of this line but I'll see if I can and update accordingly. ```rust use bevy::{prelude::*, render::view::NoIndirectDrawing}; fn main() { App::new() .insert_resource(ClearColor(Color::BLACK)) .add_plugins(DefaultPlugins) .add_systems(Startup, startup) .run(); } fn startup( mut cmd: Commands, mut meshes: ResMut<Assets<Mesh>>, mut materials: ResMut<Assets<StandardMaterial>>, mut al: ResMut<AmbientLight>, ) { al.brightness = 5000.; cmd.spawn(( Mesh3d(meshes.add(Cuboid::from_size(Vec3::new(4., 0.5, 0.1)))), MeshMaterial3d(materials.add(Color::srgb(1., 1., 0.))), Transform::from_xyz(0., 0., -2.), )); let mut id = cmd.spawn(( Mesh3d(meshes.add(Cuboid::from_length(1.))), MeshMaterial3d(materials.add(Color::srgba(0., 0., 1., 0.5))), Transform::from_xyz(-0.5, 0., 0.), )); id.clone_and_spawn() .insert(Transform::from_xyz(0.5, 0., 0.)); cmd.spawn(( Camera3d::default(), Transform::from_xyz(0., 0., 10.).looking_at(Vec3::ZERO, Vec3::Y), NoIndirectDrawing, )); } ``` ## Showcase Before <img width="178" height="202" alt="486232152-9f8685f6-fbc3-4bc1-b9bd-7e28177cc901" src="https://github.com/user-attachments/assets/2bca4f28-b956-49dc-83b4-edefef6ca595" /> After <img width="120" height="173" alt="486232412-bafd5e4a-69be-4249-894a-5f03dfe28b63" src="https://github.com/user-attachments/assets/1b911bb6-01c4-451a-b010-20aab505217e" /> Co-authored-by: Dimitrios Loukadakis <[email protected]>
Objective
Solution
#[component(clone_behavior=Ignore)]
to avoid cloning this ComponentTesting
Showcase
Before

After
