GraphUpdateScene doesn't work properly when using PolygonCollider2d

I’m using 4.2.15 free version of the package. And it contains a small bug that makes GraphUpdateScene unusable with PolygonCollider2d.
Here is the original part of code from GraphUpdateScene Apply function.

GraphUpdateObject guo;

if (points == null || points.Length == 0) {
	var polygonCollider = GetComponent<PolygonCollider2D>();
	if (polygonCollider != null) {
		var points2D = polygonCollider.points;
		Vector3[] pts = new Vector3[points2D.Length];
		for (int i = 0; i < pts.Length; i++) {
			var p = points2D[i] + polygonCollider.offset;
			pts[i] = new Vector3(p.x, 0, p.y);
		}

		var mat = transform.localToWorldMatrix * Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(-90, 0, 0), Vector3.one);
		var shape = new GraphUpdateShape(points, convex, mat, minBoundsHeight);
		guo = new GraphUpdateObject(GetBounds());
		guo.shape = shape;
	}
}

It looks like you are trying to create a new GraphUpdateObject with a shape converted from polygonCollider points. But you forgot to replace points array (which is empty, you checked it in the if statement) with pts.

var shape = new GraphUpdateShape(pts, convex, mat, minBoundsHeight);

The line above should fix this bug.

Thank you for finding this!
I will fix this!

1 Like