# Change maxPolygonVertices in Box2D?

**URL:** <https://discourse.processing.org/t/change-maxpolygonvertices-in-box2d/13383>\
**Category:** Libraries\
**Created:** [August 14, 2019, 8:09pm UTC](https://discourse.processing.org/t/change-maxpolygonvertices-in-box2d/13383 "2019-08-14T20:09:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeffthompson](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeffthompson/32/743_2.png) [@jeffthompson](https://discourse.processing.org/u/jeffthompson)\
**Post date:** [August 14, 2019, 8:09pm UTC](https://discourse.processing.org/t/change-maxpolygonvertices-in-box2d/13383/1 "2019-08-14T20:09:19Z")

</div>

I’m working on a project that uses Daniel Shiffman’s `Box2D` library to arrange a bunch of objects and have run into an issue. It seems that a polygon with more than 8 vertices throws an error, but I’d really like to change that to at least 12 or 14 (see note below).

Digging through the docs, it looks like this can be changed by a variable called `maxPolygonVertices` in the Java port (see the [Settings.java file](https://github.com/jbox2d/jbox2d/blob/83913df8678ebb1e641781becb48b19fc20b9e45/jbox2d-library/src/main/java/org/jbox2d/common/Settings.java)). But I can’t figure out if there’s a way to change that through the Processing library, or how I might mod the library to allow that, or if I need to change the Java port, then recompile both libraries?

_Note: I totally get that more vertices will slow things down, but in my case this isn’t an interactive system where performance is an issue. Basically, I want to use the robust and out-of-the-box collision that `Box2D` offers to lay out what will eventually be a print. No need for fast frame rate 🙂_

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [August 14, 2019, 8:20pm UTC](https://discourse.processing.org/t/change-maxpolygonvertices-in-box2d/13383/2 "2019-08-14T20:20:13Z")

</div>

```auto
import shiffman.box2d.*;

void setup() {
  println(org.jbox2d.common.Settings.maxPolygonVertices); // 8
  org.jbox2d.common.Settings.maxPolygonVertices <<= 1;
  println(org.jbox2d.common.Settings.maxPolygonVertices); // 16
  exit();
}

```

---

<div class="post-metadata">

**Author:** ![jeffthompson](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeffthompson/32/743_2.png) [@jeffthompson](https://discourse.processing.org/u/jeffthompson)\
**Post date:** [August 14, 2019, 9:59pm UTC](https://discourse.processing.org/t/change-maxpolygonvertices-in-box2d/13383/3 "2019-08-14T21:59:07Z")

</div>

Nice! Any reason not to just do this?

`org.jbox2d.common.Settings.maxPolygonVertices = 12;`

---

<div class="post-metadata">

**Author:** ![jeffthompson](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeffthompson/32/743_2.png) [@jeffthompson](https://discourse.processing.org/u/jeffthompson)\
**Post date:** [August 29, 2019, 6:37pm UTC](https://discourse.processing.org/t/change-maxpolygonvertices-in-box2d/13383/4 "2019-08-29T18:37:55Z")

</div>

Also, worth noting that this change must happen _before_ you call `box2d.createWorld();` otherwise it won’t work and will throw an error 🙂
