Skip to content
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

Updating Image::data does not change how the image is displayed in StandardMaterial. #17220

Open
mintlu8 opened this issue Jan 7, 2025 · 2 comments
Labels
A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior S-Needs-Design This issue requires design work to think about how it would best be accomplished

Comments

@mintlu8
Copy link
Contributor

mintlu8 commented Jan 7, 2025

Bevy version

0.15

What you did

Update an existing Image's data after it has been created and rendered at least once.

What went wrong

StandardMaterial did not update its render, despite the content of the Image asset has changed.

Additional information

Reproduction:
https://github.com/mintlu8/bevy_bug

@mintlu8 mintlu8 added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Jan 7, 2025
@mintlu8 mintlu8 changed the title Updating Image::data does not change how the image is displayed. Updating Image::data does not change how the image is displayed in StandardMaterial. Jan 7, 2025
@thebluefish
Copy link
Contributor

thebluefish commented Jan 7, 2025

See #15595 (and the related issue mention there).

Basically, you need to mutably touch the materials for it to "see" the changes in their dependent assets.

AsyncWorld.run_cached_system(
    move |mut assets: ResMut<Assets<Image>>, mut materials: ResMut<Assets<StandardMaterial>>, mut query: Query<&mut MeshMaterial3d<StandardMaterial>>| {
        let mat = query.single_mut();
        let mat_asset = materials.get_mut(mat.id()).unwrap(); // remove the `_mut` part here and observe how it breaks, due to no change detection on the underlying asset
        if let Some(img) = assets.get_mut(mat_asset.base_color_texture.as_ref().unwrap().id()) {
            for x in 0..128 {
                for y in 0..128 {
                    // Make fourth quadrant blue.
                    img.data[((y + 128) * 256 + x + 128) * 4 + 2] = 255;
                }
            }
            println!("Changed fourth quadrant to blue!");
        }
    }
)?;

@BenjaminBrienen BenjaminBrienen added A-Rendering Drawing game state to the screen S-Needs-Design This issue requires design work to think about how it would best be accomplished and removed S-Needs-Triage This issue needs to be labelled labels Jan 7, 2025
@BenjaminBrienen
Copy link
Contributor

I'm leaving this open because I'd like to know whether the API can be improved to make this more obvious.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior S-Needs-Design This issue requires design work to think about how it would best be accomplished
Projects
None yet
Development

No branches or pull requests

3 participants