Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


Validate()

Rebuild the polygon from its vertices.
Read time 1 minuteLast updated 6 days ago

Definition

  • Type: Method
  • Namespace: Unity.U2D.Physics
  • Assembly: UnityEngine.PhysicsCore2DModule
public readonly PolygonGeometry Validate()

Returns

Type

Description

PolygonGeometryThe rebuilt polygon, or an empty geometry when it cannot be rebuilt. See _isValid.

Remarks

The normals and the centroid are calculated from the vertices, replacing whatever they were set to, and the radius is kept as it is. They must still be finite to begin with, along with the radius and every vertex, because a non-finite value stops the rebuild rather than being replaced. The vertices are replaced by the convex hull of themselves, so a vertex that is concave, duplicated or too close to its neighbor is welded away or dropped. The result can therefore have fewer vertices than the geometry it was rebuilt from.