Replies: 1 comment 3 replies
-
I am not entirely sure why camera displays its contents when you have visibility set to Hidden. It appears it however will carry down to its children so that they will not show up when set to hidden, so it at least does something to that effect. Here's an example bevy file that will show a circle when Visibility of the Camera is set to Hidden and a square (which is the child of the camera) when the camera is visible. Putting children on camera's is pretty common place for things that need to follow the camera around :). If you want to see the camera in movement with the square inside it I created a demo repo here: https://github.com/johnsonjo4531/bevy_figure_8_demo use bevy::prelude::*;
use bevy::render::camera::ScalingMode;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_systems(Startup, spawn_camera)
.add_systems(Update, spawn_ball)
.run();
}
#[derive(Component, Default)]
#[require(Camera2d)]
struct MainCamera;
fn spawn_camera(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<ColorMaterial>>,
) {
commands
.spawn((
MainCamera,
Visibility::Hidden, // Since this is hidden you will see the circle toggle this line to be commented out and you should see the children
Projection::Orthographic(OrthographicProjection {
scaling_mode: ScalingMode::FixedVertical {
viewport_height: 100.0,
},
scale: 1.0,
..OrthographicProjection::default_2d()
}),
))
.with_children(|child| {
child.spawn((
Mesh2d(meshes.add(Rectangle::new(100., 100.))),
MeshMaterial2d(
materials.add(ColorMaterial::from_color(Color::srgb_u8(255, 255, 255))),
),
Transform::from_translation(Vec3::new(0., 0., -1.)),
// Visibility::Visible, // Toggle this line as commented in and it should always
// display a square as the child of the camera regardless of the camera's visibility
));
});
}
fn spawn_ball(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<ColorMaterial>>,
) {
commands.spawn((
Mesh2d(meshes.add(Circle::new(50.))),
MeshMaterial2d(materials.add(ColorMaterial::from_color(Color::srgb_u8(255, 255, 255)))),
));
} |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
It doesn't seem to do anything.
Beta Was this translation helpful? Give feedback.
All reactions