Skip to content

UI Node with absolute position seems to be incorrectly scaled #18877

Open
@rongcuid

Description

@rongcuid

Bevy version

0.15.3

[Optional] Relevant system information

  • Mac M2

If your bug is rendering-related, copy the adapter info that appears when you run Bevy.

2025-04-18T21:29:44.996370Z  INFO bevy_diagnostic::system_information_diagnostics_plugin::internal: SystemInfo { os: "MacOS 15.3.1 ", kernel: "24.3.0", cpu: "Apple M2", core_count: "8", memory: "24.0 GiB" }
2025-04-18T21:29:45.084210Z  INFO bevy_render::renderer: AdapterInfo { name: "Apple M2", vendor: 0, device: 0, device_type: IntegratedGpu, driver: "", driver_info: "", backend: Metal }
2025-04-18T21:29:45.248183Z  INFO bevy_winit::system: Creating new window "App" (0v1#4294967296)

What you did

I spawn a crosshair image using the following code:

pub fn spawn_crosshair(mut commands: Commands, window_query: Query<&Window, With<PrimaryWindow>>) {
    if let Ok(window) = window_query.get_single() {
        let crosshair_size = 8.0;
        commands
            .spawn(Node {
                width: Val::Percent(100.0),
                height: Val::Percent(100.0),
                ..default()
            })
            .with_children(|p| {
                p.spawn((
                    ImageNode::solid_color(Color::srgb(0., 1., 0.)),
                    Node {
                        width: Val::Px(crosshair_size),
                        height: Val::Px(crosshair_size),
                        position_type: PositionType::Absolute,
                        left: Val::Px(window.width() / 2.0 - (crosshair_size / 2.0)),
                        top: Val::Px(window.height() / 2.0 - (crosshair_size / 2.0)),
                        ..default()
                    },
                ));
            });
    }
}

What went wrong

If it's not clear, break this out into:

  • Crosshair (square) should appear at the center of the window
  • Crosshair actually appear at lower-right corner
  • If I divide the width and height by 4, crosshair appear at the center
  • However, scaling factor is reported to be 1. Physical width/height are also same as logical.
  • If I use percentage instead of absolute size, positioning is correct.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-UIGraphical user interfaces, styles, layouts, and widgetsC-BugAn unexpected or incorrect behaviorS-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