Skip to content

Fix CollisionShape2D clip children - #109165

Open
DirtyDoggo wants to merge 9 commits into
godotengine:masterfrom
DirtyDoggo:collision_shape_2d_crop_fix
Open

DirtyDoggo wants to merge 9 commits into
godotengine:masterfrom
DirtyDoggo:collision_shape_2d_crop_fix

Conversation

@DirtyDoggo

@DirtyDoggo DirtyDoggo commented Jul 31, 2025 •

Copy link
Copy Markdown

Fixes #108800

CollisionShape2D debug draw shape now doesn't get cropped by the parent.

Done by making a separate CanvasItem at the root of the scene tree that gets it's visuals and transform updated by the base node.

This issue is still present in certain other nodes (RayCast2D and Path2D were tested, but there are probably many more), so maybe those should be fixed in separate PR the same way too?

@DirtyDoggo
DirtyDoggo requested review from a team as code owners July 31, 2025 14:45
@KoBeWi KoBeWi added this to the 4.5 milestone Jul 31, 2025
@AThousandShips AThousandShips changed the title CollisionShape2D debug draw crop fix Fix CollisionShape2D clip children Jul 31, 2025
@DirtyDoggo
DirtyDoggo force-pushed the collision_shape_2d_crop_fix branch from 1605524 to fccf6a5 Compare August 1, 2025 10:21
@DirtyDoggo

Copy link
Copy Markdown
Author

Revision #2: Did some testing and found some bugs that needed fixing, so I added them. Also added debug ifdefs where they made sense.

@DirtyDoggo
DirtyDoggo force-pushed the collision_shape_2d_crop_fix branch 3 times, most recently from c8d4112 to 9f5de63 Compare August 1, 2025 12:28
@DirtyDoggo
DirtyDoggo force-pushed the collision_shape_2d_crop_fix branch 2 times, most recently from a786e61 to 0891768 Compare August 8, 2025 16:30
@DirtyDoggo
DirtyDoggo requested a review from a team as a code owner August 8, 2025 16:30
@DirtyDoggo
DirtyDoggo force-pushed the collision_shape_2d_crop_fix branch from 0891768 to 694b55b Compare August 8, 2025 19:12
@DirtyDoggo

Copy link
Copy Markdown
Author

Based on discussion in the original issue thread, moved the code to CanvasItem so that it can be reused for all the other nodes with similar situation.

I will look into doing the same for all the other related nodes in the coming days, along with fixing based on feedback.

Known issue is that the Z of the debug graphic doesn't update until the node itself updates transform. I can fix it for the local z_order but not the one inherited from parents (maybe that would be enough?). I would prefer not to have it like it was in the reference class where it's always on top, but maybe that was the intended solution here?

@DirtyDoggo
DirtyDoggo force-pushed the collision_shape_2d_crop_fix branch from 694b55b to 0e9ec8f Compare August 12, 2025 16:32
@DirtyDoggo

Copy link
Copy Markdown
Author

Massive update made covering over 20 files, including fixing all the debug drawing nodes. Check commit description for more info.

This has been done by adding the debug_canvas_item that is parented to the treet root to the base canvas_item.
All the 2d nodes that did debug drawing now use this system, including:
path_2d
skeleton_2d
visible_on_screen_notifier_2d
navigation_link_2d
navigation_obstacle_2d
navigation_region_2d
collision_polygon_2d
collision_shape_2d
ray_cast_2d
shape_cast_2d
damped_spring_joint_2d
groove_joint_2d
pin_joint_2d

While at it, added DEBUG_ENABLED ifdefs to all the debug drawing functions to all these classes and remove their customly setup debug canvas items.
As a bonus, fixed drawing of the edge_connection between navigation regions.

Known issue is that if the z of the node updates via parent z updates, the z of the debug shape will not update until next redraw, but I believe it's better than having it be on top all the time.
@DirtyDoggo
DirtyDoggo force-pushed the collision_shape_2d_crop_fix branch from 0e9ec8f to 6d25f1b Compare August 12, 2025 16:44
@Repiteo Repiteo modified the milestones: 4.5, 4.x Sep 18, 2025
@KoBeWi

This comment was marked as resolved.

Comment thread scene/main/canvas_item.h Resolved
Comment thread scene/main/canvas_item.cpp Resolved
Comment thread scene/main/canvas_item.cpp Resolved
Comment thread scene/main/canvas_item.cpp Resolved
Comment thread scene/main/canvas_item.cpp Resolved
Comment thread scene/2d/skeleton_2d.cpp Resolved
Comment thread scene/2d/physics/shape_cast_2d.cpp Resolved
Comment thread scene/main/canvas_item.h Resolved
@DirtyDoggo
DirtyDoggo requested a review from a team as a code owner October 13, 2025 07:58
Comment thread scene/main/canvas_item.cpp Resolved
Comment thread scene/main/canvas_item.cpp Resolved
Comment thread scene/main/canvas_item.cpp Resolved
Comment thread scene/main/canvas_item.h Resolved
@DirtyDoggo
DirtyDoggo requested a review from KoBeWi October 23, 2025 08:42
@KoBeWi

KoBeWi commented Oct 23, 2025

Copy link
Copy Markdown
Member

The shape ignores parent modulate:

godot.windows.editor.dev.x86_64_eKcvvccgEz.mp4

Though if it can't be solved easily then maybe it's fine.

@KoBeWi KoBeWi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, aside from the above issue.

The CanvasItem changes could use a review from core team.

@KoBeWi KoBeWi modified the milestones: 4.x, 4.6 Oct 23, 2025
@DirtyDoggo

Copy link
Copy Markdown
Author

The shape ignores parent modulate:
godot.windows.editor.dev.x86_64_eKcvvccgEz.mp4

Though if it can't be solved easily then maybe it's fine.

I assume it's similarly difficult thing to fix as the z_index update when parents change, since it doesn't have a notification to catch.

@KoBeWi

KoBeWi commented Oct 23, 2025 •

Copy link
Copy Markdown
Member

I realized that TileMapLayer also has internal CanvasItems and it properly updates modulate and z_index. So it is doable

EDIT:
Ah no, the problem is that debug canvas item is not a child of the node. Maybe it's worth documenting at least, idk.

Comment thread scene/2d/physics/collision_shape_2d.cpp Resolved
Comment thread scene/main/canvas_item.h Resolved
Comment thread scene/main/canvas_item.cpp Resolved
Comment thread scene/main/canvas_item.h Resolved
Comment thread scene/main/canvas_item.h Resolved
Comment thread scene/main/canvas_item.cpp Resolved
Comment thread scene/2d/physics/shape_cast_2d.cpp Resolved
Comment thread scene/2d/physics/ray_cast_2d.cpp Resolved
@Repiteo
Repiteo requested a review from Ivorforce October 28, 2025 16:51
@Repiteo Repiteo modified the milestones: 4.6, 4.x Jan 26, 2026
@YeldhamDev

Copy link
Copy Markdown
Member

Are you still able to work on this PR?

@DirtyDoggo

DirtyDoggo commented Nov 26, 2026 via email

Copy link
Copy Markdown
Author

@YeldhamDev YeldhamDev modified the milestones: 4.x, 4.9 Nov 26, 2026
@DirtyDoggo

Copy link
Copy Markdown
Author

Having synced locally and built the engine, suprisingly, a lot has changed in a year, so it seems I will need to fix some stuff and test more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Clip children clips CollisionShape2D visualization.

5 participants