In Season 4 of “How I Met Your Mother,” Lily disappears for three episodes. In Episode 20, “Mosbius Designs,” Barney tells Lily a dirty joke, with which she replies, “I cannot hang out with you anymore.” In Episode 23, “As Fast as She Can,” Lily walks into MacLaren’s Pub, tells Barney that she took some time to think about the joke, and found the humor in it.
It turns out, Alyson Hannigan took a brief hiatus from the show after giving birth to her first child, so the writers wrote this storyline to explain Lily’s disappearance. In a 2009 interview with The Chicago Tribune, Craig Thomas — the show’s co-creator and executive producer — talked about the challenges of filming around the pregnancy of not one, but two main cast members. Cobie Smulders also got pregnant at the same time as Hannigan, which was a surprise for the creators. “After the shock wore off, we found a way to write around it or have fun with it,” Thomas said, explaining how the writers winked at viewers by hiding Hannigan’s pregnancy in plain sight.
When it came to Hannigan’s hiatus, Thomas said they used it as an opportunity to give Barney and Marshall’s friendship more screen time. Meanwhile, Smulders and Hannigan used their time on set to share their pregnancy experiences with each other. In a 2009 interview with People, Smulders said, “you have babies on the brain, and you can’t help but talk about it a lot. From creams, doctors, birth methods, dilation…You talk about everything.”