Show the shape of a Area2D's collider in-game

Godot Version

4.2.1

Question

I have a Area2D with a CollisionPolygon2D child. I’m trying to show the shape of this Area2D in-game by assigning it a color or a texture (not for debug purposes but for actual in-game use).

I see lots of folks have tried to do this, but I have not been able to get it to work:
https://godotforums.org/d/18855-how-to-give-a-color-to-area2d

Thanks

I can’t see why it didn’t work.
If it is a rectangle area then just add a ColorRect as a child of the Area2D and set the size and extents the same as the CollisionShape2D.

The problem is that it’s not a rectangle but a CollisionPolygon2D (with quite a complex polygon shape).

I think you can use _draw method for this case.

1 Like

Thank you @supernovafiles, I was able to do the following (C#):

public override void _Draw()
{
base._Draw();
DrawColoredPolygon(myCollisionPolygon2D.Polygon, highlightColor);
}

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.