Moving and SweepTesting a kinematic Rigidbody multiple times within a single FixedUpdate() call

I’m writing some custom movement code for a 2D platformer character, using a kinematic Rigidbody and a C# script that can call SweepTest() and MovePosition() two or more times each during its FixedUpdate() function. However, calling rigidbody.MovePosition() doesn’t seem to immediately update the rigidbody’s position variable to the new position. For example the following function will print the same value for position 1 and position 2:

void FixedUpdate () {
    Debug.Log("Position 1: " + rigidbody.position);
    rigidbody.MovePosition(rigidbody.position + new Vector3(0.0f, 1.0f, 0.0f));
    Debug.Log("Position 2: " + rigidbody.position);
}

I assume this means that the Rigidbody is only being moved at the end of the physics step. If this is the case, how can I move a kinematic Rigidbody and call SweepTest() from its new position in the same FixedUpdate() call?

I actually encountered this same issue all these years later in 2022. The answer appears to be to mix Rigidbody.MovePosition and Rigidbody.position. While you are sweeptesting, update the rigidbody’s position with Rigidbody.position += displacement or Rigidibody.position = resolutionPosition. Once nothing has been detected by the sweeptest, or some other condition allows the rigidbody to move freely without colliding, call Rigidbody.MovePosition(Rigidbody.position + someValue).

You could also save the cast origin and desired final position in variables, and use the new origin for every sweeptest, only moving the rigidbody once at the end with Rigidbody.MovePosition(finalPosition).