Add/Remove shapes to PhysicsBody

Hi,

I have big layer as game world which has lot of boundaries where physics collision should happen. To optimise and get it faster, I’m trying to calculate positions of shapes and create/add only visible ones to layer. But the problem is that I can do this on constructing layer but not later for example in update(dt) method.

_body = PhysicsBody::create();
_body->setDynamic(false);
_body->setGravityEnable(false);
setPhysicsBody(_body);

Then in update physics calculate points and remove old ones and add new ones:

_body->removeAllShapes()

and

auto shape = body->addShape(PhysicsShapeEdgeSegment::create(p1, p2));

Now _body has new shapes but those are not drawn if have physics debug draw enabled. Also collision does not happen anymore.

So how to add/remove physic shapes dynamically?