Why does a Polygon2D texture change its appearance?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By jarlowrey
:warning: Old Version Published before Godot 3 was released.

If you attempt to set the texture of a polygon2D and define some verticies via the pencil tool, these giant gray bars come shooting off. Why is this?

enter image description here

Also since we’re on the subject, how do Polygon2D and CollisionPolygon2D fit together? It looks like you can make a polygon with Polygon2D in the editor, so whats the point of CP2D?

:bust_in_silhouette: Reply From: Zylann

Your texture looks like this when applied on the polygon because the UVs (also known as “texture coordinates”) of the polygon extend beyond the image size range. Your image is set to not repeat, so Godot renders it by clamping the pixels out of range, and you see stretched edges.

The UVs are like this because you didn’t define any, so Godot takes the position of the points as UVs, which of course extend beyond image size as you make the polygon bigger.
If you want to edit the UVs, click the small “uv” button on top of the viewport when your polygon is selected.

CollisionPolygon2D is separate because:

  • you could want a different collision polygon than the one you see
  • you could use that polygon for different purposes and then different design
  • you could want an invisible collision, as well as no collision and just a visual
  • It is part of the physics engine, while Polygon2D is only rendering.

Thanks for the great answer! Had no idea what the UV stuff was for, thanks for letting me know. Can you use P2Ds in collisions as if they were CP2D, or are they entirely constrained to rendering, ie would you need both for some reason?

jarlowrey | 2017-09-08 21:20