This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes


I am hoping to use Node2D.drawpolygon() to draw in a nice overlay for a section of my screen. I am calculating an outline for an area, and feeding that set of points ([Vector2]) to the drawpolygon method. I have verified that the method gets the data correctly and that it looks like a complete shape, but I am getting a "Bad Polygon!" error from the engine.

Here is my code:

extends Node2D

var _outline_polygon = Vector2Array()
var _colors = ColorArray([Color(0,1,0,.5)])
var _drawing = false

func _ready():

func set_polygon(poly_path):
    #generate the polygon that represents this room
    _outline_polygon = poly_path
    print(get_name(), ": ", _outline_polygon)
#   _drawing = true

func _process(delta):

func _draw():
    if _drawing:
        draw_polygon(_outline_polygon, _colors)

Here is an example of the content of the outlinepolygon variable:

room_8: [(256, 448), (320, 448), (320, 448), (384, 448), (384, 448),
(384, 512), (384, 512), (384, 576), (384, 576), (320, 576), (320,
576), (256, 576), (256, 576), (256, 512), (256, 512), (256, 448)]

Here is the error I am getting - sorry about the image link, it is a screen shot. But basically says "Bad Polygon!" and seems to be coming from something called: visualserverraster.cpp in the back end.

Any ideas? What should I be passing into the function to get a nice polygon out on the other side?

in Engine by (41 points)
edited by

1 Answer

+3 votes
Best answer

Your polygon has duplicate points.
After experiencing a bit, I found draw_polygon will work only if those conditions are fulfilled:

  • There must be no duplicate points
  • The area must not be zero
  • The polygon must not fold onto itself
  • The number of points you provide must be the same as the number of colors (even if all colors are the same). The same rule applies to UVs if provided.
by (29,510 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.