★ ★ ★ ½

Boy meets girl. Boy and girl flirt, dance around the possibility of dating each other, but decide (for reasons that might be believable or totally contrived) to just stay friends. Boy and girl see other people, but it never quite feels right. Why can’t either of them find someone smart and sexy and interesting, someone like…their platonic pal? Finally, it dawns on one of them that their friendship has really been a romance in disguise, and that the perfect person was right there all along.

1989’s When Harry Met Sally wasn’t the first movie to suggest that longtime friends could make good life partners, but it remains the most enduring spin on that idea, and its success turned this basic story line into the default setting for romantic comedies. Even now, more than 25 years later, no one has come up with a different formula that’s compelling and flexible enough to take its place, and Sleeping With Other People is the latest attempt to take these tropes and try to find something new within them; writer-director Leslye Headland even described the film as “When Harry Met Sally with a--holes.” But while the movie introduces both of its leads as awful people, it quickly backs away from this idea and settles into being a rom com that’s raunchier on the surface, yet just as conventional deep down.

Those aforementioned leads are Jake (Jason Sudeikis) and Lainey (Alison Brie), who lose their virginity to each other in college during a one-night stand, and meet again years later when they both attend the same meeting for sex addiction. That’s a hell of a high-concept setup, but the film doesn’t really commit to it, dialing its characters back from serial cheaters to just two people who are unlucky in love: Jake is a horndog unable to settle down because he hasn’t found the right woman, while Lainey can’t break free of a toxic affair she’s been having with a married OB-GYN (Adam Scott) she’s been in love with since college. The pair, now reunited, decide that they’re obviously too dysfunctional to be a couple together, but they might be able to help each other with their problems.

If you’ve read this far, you can probably guess where this is going. What sets Sleeping With Other People apart from the pack isn’t just that it’s trying to be much dirtier than your average rom com (the standout scene involves Jake teaching Lainey how to pleasure herself, with an ice-tea bottle as a visual aid), but that it wants to depict its characters as flawed, recognizably human individuals rather than easy stereotypes, a move that’s sometimes effective and sometimes out of sync with the needs of the story. Nowhere is this better seen than in Lainey’s relationship with the married Matthew Sobvechik. Virtually any other film would have made him an insufferable boor or an abusive jerk, a clear villain along the lines of Bradley Cooper’s character in Wedding Crashers. Instead, Matthew is someone who’s simply too weak-willed to break off the affair, and Scott plays him as a WASPy, charisma-free non-entity. It’s an intriguing take on this sort of character — and it turns Lainey’s love for him into a tribute to the impossibility of understanding sexual attraction — but it makes the scene where Jake violently confronts him feel like it’s happening in a completely different movie, as if Headland had to suddenly reconfigure Matthew into a bad guy when she realized that she didn’t know how to resolve this plot line with the same degree of nuance that the setup required.

Despite the tension between the complexity of the characters and the formulaic nature of the plot, Sleeping With Other People is still an entertaining run through some familiar story beats. It helps that Jake and Lainey’s friends and confidantes are played by gifted comic actors, and written with a level of specificity that’s rare for a romantic comedy. In particular, Jason Mantzoukas and Andrea Savage are terrific as a married couple who are good friends with Jake, and who are concerned that he’s in danger of forever being that weird single guy at their parties. They’re two people whose marriage-with-kids leaves them frequently frustrated and exhausted, yet still love each other and get along very well; Headland must have realized what she had in these two, since they’re the stars of a mid-credits sequence in which they riff back and forth with the ease and inside jokes of a couple who have been married for a while. (That said, it’s a little weird that they host a kids’ birthday party that Jake and Lainey end up attending while high on ecstasy. Are young parents these days really this cool with adults rolling on E hanging out with their children? Even if all it leads to is Lainey teaching the youngsters a choreographed dance set to David Bowie’s “Modern Love”?)

Sleeping With Other People is consistently funny and willing to go to some unusual detours during a journey whose destination is never in doubt; it keeps flirting with interesting ideas without committing to them, like a sequence in which Jake and Lainey keep in touch via text message over the course of several dates, or Jake’s complicated relationship with Paula (Amanda Peet), a divorced woman who’s also his boss, and whose backstory is fascinating enough to serve as the basis of its own movie. In the end, Headland isn’t able to use her material to blow up rom-com conventions and build something new in their place, but she’s still crafted one of the best, funniest riffs yet on When Harry Met Sally’s “can men and women be friends?” dilemma.