Skip to content

MeshMaterial3d added in PostUpdate sometimes do not get sent to the RenderApp #21290

@hukasu

Description

@hukasu

Bevy version and features

0.17.0-rc.2

[Optional] Relevant system information

2025-09-30T00:47:58.160894Z  INFO plugin build{plugin="bevy_diagnostic::DiagnosticsPlugin"}: bevy_diagnostic::system_information_diagnostics_plugin::internal: SystemInfo { os: "Linux (NixOS 25.05)", kernel: "6.12.34", cpu: "Intel(R) Core(TM) i7-14700KF", core_count: "20", memory: "31.2 GiB" }
2025-09-30T00:47:58.413688Z  INFO plugin build{plugin="bevy_render::RenderPlugin"}: bevy_render::renderer: AdapterInfo { name: "NVIDIA GeForce RTX 4060 Ti", vendor: 4318, device: 10243, device_type: DiscreteGpu, driver: "NVIDIA", driver_info: "570.153.02", backend: Vulkan }

What you did

I am loading some files from an old game and they use negative scale on meshes to mirror them. I made a change to only add MeshMaterial3d after TransformSystems::Propagate to be able to query the GlobalTransform for the updated scale. This is needed because i need to set some shader defs if the scale is negative on 1 or 3 axis.

What went wrong

Some times the program runs, some times it doesn't with

   0: bevy_ecs::system::function_system::system
           with name="bevy_pbr::material::specialize_material_meshes"
             at /home/hukasu/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/bevy_ecs-0.17.0-rc.2/src/system/function_system.rs:49

thread 'main' panicked at /home/hukasu/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/bevy_pbr-0.17.0-rc.2/src/material.rs:973:79:
called `Option::unwrap()` on a `None` value

Additional information

I imagine that there is a system set that i need to have my system run before for it to work consistently. Here is my code

app.add_systems(
    PostUpdate,
    invert_material.after(TransformSystems::Propagate),
);

fn invert_material(
    mut commands: Commands,
    rsms: Populated<
        (NameOrEntity, &RsmMaterials, &GlobalTransform),
        (With<Mesh3d>, Without<MeshMaterial3d<RsmMaterial>>),
    >,
) {
    for (rsm, rsm_materials, global_transform) in rsms.into_inner() {
        let inverted_axis = global_transform.scale().is_negative_bitmask().count_ones();
        let material = if inverted_axis % 2 == 0 {
            rsm_materials.base.clone()
        } else {
            rsm_materials.inverted.clone()
        };
        commands.entity(rsm.entity).insert(MeshMaterial3d(material));
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-RenderingDrawing game state to the screenC-BugAn unexpected or incorrect behaviorP-CrashA sudden unexpected crashS-Needs-InvestigationThis issue requires detective work to figure out what's going wrong

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions