bevyengine / bevyengine/bevy

UI Node with absolute position seems to be incorrectly scaled

Open
#18,877 0 comments 0 reactions 0 assignees View on GitHub
A-UI C-Bug S-Needs-Investigation
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 16h
Merged PRs (30d)
171

Description

## 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.

```ignore
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:

```rs
pub fn spawn_crosshair(mut commands: Commands, window_query: Query<&Window, With>) {
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.

Contributor guide

Open the contributing guide

Research direction

Start with the spawn_crosshair entry point and reproduce the behavior on Bevy 0.15.3 using the supplied absolute-position and percentage-position examples. Read the UI Node layout and window sizing behavior involved in absolute positioning; done means the 8px crosshair is centered with absolute pixel offsets without requiring division by four.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
game-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.