Skip to content

New sprites / mesh 2d become invisible when there are about 1000+ on the screen #20026

Open
@svenallers

Description

@svenallers

Bevy version

0.16.1

Relevant system information

2025-07-08T06:43:09.456225Z  INFO bevy_diagnostic::system_information_diagnostics_plugin::internal: SystemInfo { os: "Windows 11 Home", kernel: "26100", cpu: "12th Gen Intel(R) Core(TM) i7-12700H", core_count: "14", memory: "31.7 GiB" }    
2025-07-08T06:43:09.969508Z  INFO bevy_render::renderer: AdapterInfo { name: "NVIDIA GeForce RTX 3070 Ti Laptop GPU", vendor: 4318, device: 9440, device_type: DiscreteGpu, driver: "NVIDIA", driver_info: "576.88", backend: Vulkan }

What you did

I wrote a simple benchmarking tool to see how Bevy behaves with a high amount of entities and realized that new sprites become invisible as soon as there are more than 1000 entities existing. You just see a short blink of the new sprite when it got spawned but it disappears immediately afterwards. I did the same test with Mesh2d and MeshMaterial2d but got the same result.

Here the code to reproduce the issue:

use bevy::diagnostic::{EntityCountDiagnosticsPlugin, FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin};
use bevy::prelude::*;
use bevy::window::WindowResolution;

pub const WINDOW_WIDTH: f32 = 1024.0;
pub const WINDOW_HEIGHT: f32 = 768.0;

pub const MAX_X: f32 = WINDOW_WIDTH / 2.0;
pub const MAX_Y: f32 = WINDOW_HEIGHT / 2.0;

#[derive(Component)]
pub struct Direction(Vec2);

#[derive(Resource, Default)]
pub struct LastSpawn{
    seconds: f32,
    direction: Vec2,
    amount: usize
}

fn main() {
    App::new()
        .add_plugins((
            DefaultPlugins.set(WindowPlugin {
                primary_window: Some(Window {
                    title: "Benchmark".into(),
                    resolution: WindowResolution::new(WINDOW_WIDTH, WINDOW_HEIGHT),
                    ..default()
                }),
                ..default()
            }),
            EntityCountDiagnosticsPlugin::default(),
            FrameTimeDiagnosticsPlugin::default(),
            LogDiagnosticsPlugin::default(),
        ))
        .insert_resource(ClearColor(Color::BLACK))
        .insert_resource(LastSpawn{seconds: -1.0, direction: Vec2::new(1.0, 0.0), amount: 0})
        .add_systems(Startup, setup)
        .add_systems(Update, (spawn_sprite, move_sprite))
        .run();
}

fn setup(mut commands: Commands) {
    commands.spawn(Camera2d);
}

fn spawn_sprite(mut commands: Commands,
                mut last_spawn: ResMut<LastSpawn>,
                time: Res<Time>) {
    if last_spawn.seconds < time.elapsed_secs().floor() {
        last_spawn.seconds = time.elapsed_secs().floor();
        let next_amount = last_spawn.amount + 5;
        last_spawn.amount = next_amount;
        for _ in 0..next_amount {
            let next_direction = last_spawn.direction.rotate(Vec2::new(0.95, 0.05));
            last_spawn.direction = next_direction;
            commands.spawn((Direction(next_direction),
                            Sprite::from_color(Color::srgb(1.0, 0.0, 0.0), Vec2::new(1.0, 1.0)),
            ));
        }
    }
}

fn move_sprite(mut query: Query<(&mut Transform, &mut Direction)>, time: Res<Time>) {
    for (mut transform, mut pedestrian) in query.iter_mut() {
        if transform.translation.x.abs() > MAX_X || transform.translation.y.abs() > MAX_Y {
            pedestrian.0 = pedestrian.0.rotate(Vec2::new(0.9, -0.1));
        }
        transform.translation += Vec3::from((pedestrian.0.normalize() * time.delta_secs() * 10.0, 0.0));
    }
}

What went wrong

The newly spawned Sprites just blink up. I was expecting that they stay visible

Additional information

I made a video of the issue. The blinking is hard to see in the video, but you can see it when you look closely. I was not able to get a better video. It is very easy to spot in reality

bevy_stops_rendering.mp4

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-BugAn unexpected or incorrect behaviorS-Needs-TriageThis issue needs to be labelled

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions