My serialization routine works great except for 1 tiny issue

If the revolute joint that had been constraining two bodies was distended (a bit "out of joint") at the instant I serialize then when I deserialize (both bodies and the joint) the joint is permanently stretched.

Is there any way to tell the solver to keep trying to pull the bodies together?

Or could an optional setting be added to make a revolute joint created without common anchor points pull them together (probably around the first body's joint anchor point)? That would be really cool!

I realize I'm probably going about this in a weird/wrong manner, but I'm new. Anyway thanks for any pointers/replies!

Edit:

It looks like what I'm trying to do is make the point-to-point constraint use the same point even if, because of what I described above, the 2 points were in different places when the serialization/deserialization took place.

Is there a way to change one of the points in the joint's point to point constraint after the fact in this manner?
You need to serialize the local anchor points. Don't use the initialize function in the joint definition, instead set the local anchor points directly.
Erin! I was just about to submit the following when I saw your reply! I actually figured it out on my own!

Ok, I finally fixed it 😀

All I had to do was save off the jointDef's localAnchorA and localAnchorB (after initializing the jointDef for the very first time).

Then when deserializing I took the saved localAnchorA and localAnchorB and set new jointDef to use them.

I think this worked because, in Box2d localAnchorA is the joint's local anchor point relative to body1's origin and localAnchorB is the joint's local anchor point relative to body2's origin. (localAnchorA defines how far from the body's origin anchor A of the joint is attached) This is what the solver is trying to get back to.

I accidentally set both of these local anchors to 0,0 and suddenly both anchor points of the joint were anchored directly at the body's origin. That was the clue I needed. Anyway, seems obvious now. Hope this helps someone else!

Original thread: https://box2d.org/forum/viewtopic.php?t=4522