How to ensure all contacts are seen?

I have a save process that saves the locations of all of the non-static objects. Loading the game recreates the objects in their saved positions, with a new World. However, if I try to find which bodies are touching other bodies, this doesn't work, because the world has not processed anything yet. So, after loading a game, I need to tell it to update at least once to get all the contacts set up for later. What's the fastest way for me to do this?

Would this work:
Code:
//Load game state
world.update(0,0);
Or do I need to pass in something more realistic, like a regular tick interval?
Could you save contact information along with the rest ? I mean, in some custom format of yours.
I shouldn't need to save contact information, I get it from the world and it's automatically updated by the world every tick. I just call body.getBodiesInContact or something like that. It works after world.update runs once, but not before.
I did this at one point, to update contacts without telling the World to step:
world.m_contactManager.collide();

I had to hack World to make the contact manager public. I wasn't ever stepping the World involved, though, so I don't know whether my hack is compatible with stepping. I suspect it is.

But if a full step across a zero-length time interval does the job for you and doesn't seem to ruin anything, then maybe you should just go with that, unless an expert chimes in here to say you shouldn't. The zero-duration update doesn't take too long, does it? I mean, if your world is simple enough for you to be simulating it in real time (which presumably you are doing at some point), then surely an occasional save/load action can afford to spend the time needed for a single simulation step.
Well, I haven't actually tried it with a 0-length update, because I'm not sure if it will work, or if it does, I'm not sure if it will work entirely, or break something else, because that seems like an edge-case that wouldn't be tested well.
I've just tried it in my program--instead of using stepSize, I used (random.nextBoolean() ? stepSize : 0). More or less. My simulation looked fine; only the frame rate appeared to be harmed.

The source code for World.step() shows why:

// Update contacts.
m_contactManager.collide();

// Integrate velocities, solve velocity constraints, and integrate positions.
if (step.dt > 0.0f) {
solve(step);
}

// Handle TOI events.
if (m_continuousPhysics && step.dt > 0.0f) {
solveTOI(step);
}

Collision always happens, but the big body-movement work in solve() only happens if the time step is positive. I don't know the intention here for certain, but it does look like somebody has prepared the way for you to use a zero-length time step to solve your problem.

(I'd shut up and let the experts explain, but this subforum is short on experts.)
You can solve this by refiltering your shapes.

Code:
for( Body b = world.getBodyList(); b != null; b = b.getNext() )
{
   for( Shape s = b.getShapeList(); s != null; s = s.getNext() )
   {
      world.refilter( s );
   }
}


You can probably manage to do this without a nested for loop, but just for simplicity sake...
Just do it one time after creating all bodies in the Box2D world.
Thank you. This sounds like exactly what I need.

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