godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
89.16k stars 20.21k forks source link

Sizing artifacts for CollisionShape2Ds #96966

Open Awfyboy opened 1 week ago

Awfyboy commented 1 week ago

Tested versions

System information

Windows 11 - Godot v4.3 - Forward+ Renderer - Intel UHD Graphics 630

Issue description

godot_col_artifact

When changing the size of a CollisionShape2D, there appears to be some scaling artifacts that glitches the visual of the shape. The size is correct in the inspector but incorrect in the editor so it appears to be a visual bug. Collisions also seem to work fine.

Steps to reproduce

  1. Add a CollisionShape2D into the scene.
  2. Add a new shape Resource then try changing the size of the shape.
Awfyboy commented 1 week ago

Oh, huh. I just turned off 'Snap 2D Transforms to Pixels' and now the issue is gone.

AThousandShips commented 1 week ago

That helps in identifying what's causing this, it probably forces the grab handles to position themselves like that, and the way the box jumps back and forth

I'd say it shouldn't do that but unsure how to get around it in the editor

lpenguin commented 1 week ago

Can confirm the bug for Sprite 2D too, and I guess for other CanvasItems where the pivot is not in (0, 0) image

Found the suspicious code: https://github.com/godotengine/godot/blob/74de05a01c8716a42d4e3427f607d7bea76b35e5/servers/rendering/renderer_canvas_cull.cpp#L287-L290

If I comment this out, the rendering comes back to normal

Awfyboy commented 6 days ago

Until the bug can get fixed, the way I solve it now is, I turn off 'Snap 2D Transform to pixel' in the project settings, then turn it on when the game starts using an AutoLoad script. That way snapping is turned off in the editor but in-game the pixels get rounded off properly, so in the editor sizing works properly as well. I kind of need that snapping option for pixel art games so for the time being this workaround is fine:

extends Node

func _ready() -> void:
    RenderingServer.viewport_set_snap_2d_transforms_to_pixel(get_viewport().get_viewport_rid(), true)