When writing fiction I outline and write in "waves" (there's an actual term for this technique but I always forget what it is).
So, I write a skeletal outline that shows me what I'm starting with and where I'm ending up, then I sprinkle some details and ideas โ some of them purely speculative and contradictory โ into the middle. Then I start writing, not stopping until I have a handle on at least some of my characters, whether or not they're working, and whether or not the plot still makes sense with them in it.
Then I go back to the outline and really flesh it out, adding and discarding ideas with abandon. After that I write some more, then go back to the outline, and so forth until I'm either sure that I'm going to use these characters to get to the end that I wanted or faced with the fact that I can't.
After that it's a three-pronged approach: 1) going back and editing earlier writing so that it fits whatever the story's turning into and I'm not proceeding from an unstable foundation, 2) modifying the outline in response to changes/new ideas as they develop, and 3) new writing. I also keep two other documents at hand: a calendar/itinerary so I know where my characters are and what they're doing at any given time, and a character description document so I don't accidentally lengthen someone's hair or have them experimenting with riding crops five years before the first relationship in which they explored BDSM.
If I get stuck on a point and can't outline my way out of it I'll open a second copy of my outline, drop the cursor at the problematic point, and write my way through it. Short, choppy writing that's badly punctuated and often all lower-case, typing as fast as I can just to pull ideas out of my head as quickly as possible and without second-guessing. Cocktails can be extremely helpful when the blockage is especially severe.
The first two stories I posted ended up exactly the way I envisioned them, virtually from the beginning. Then again I was using someone else's structure so that's not particularly surprising.
In its original outline, the story I'm posting right now ended exactly the opposite of the way it's going to end now. It was one of those situations where I realized about halfway through that I was clinging to what I hoped would happen rather than what rather obviously had to happen. Thankfully, it wasn't a change that required me to start from scratch. All it required was the addition of a new final chapter, plus a prologue and an epilogue. (On the other hand, the epilogue's just shy of 50,000 words...)