Some writers invent their plots on the fly.
A. E. Van Vogt, when he wanted to know what was going to happen next to Gilbert Gosseyn, would lie down and take a little nap. Whatever he dreamed would become the newest plot twist. Other writers plot carefully and plant clues along the way. Isaac Asimov, when he wrote Second Foundation , knew exactly where the novel was going, so that the ending seems both surprising and inevitable. In SF television and movies, we have seen both kinds of plotting.