Not acting your age proves to have serious drawbacks in Noah Baumbach’s “While We’re Young,” which proves a far more successful attempt to navigate the waters of incipient middle age than Judd Apatow’s “This is 40” proved a few years ago. It isn’t as sharp or consistent as “Greenberg,” Baumbach’s previous collaboration with Ben Stiller, but while uneven, its high points outnumber the low ones.

Stiller plays Josh Svebnick, mid-forties documentary filmmaker based in New York City. Josh is the sort of character that Woody Allen would once have played (and written): a chronic complainer who’s unnerved by signs of oncoming physical debilitation like the beginnings of arthritis, and mired in trying to finish up a project he’s been working on for ten years—a rambling discourse about everything wrong with America focusing on the analysis of a caustic professor (Peter Yarrow). He and his editor Tim (Matthew Mayer) have got the rush cut of this veritable “Heaven’s Gate” of documentaries down to a cut of 6½ hours, but they’re still shooting footage for it. Nor is Josh’s home life entirely happy. He and wife Cornelia (Naomi Watts), the daughter of revered documentarian Leslie Breitbart (Charles Grodin), seem at a loss, especially since they no longer have much in common with their best friends Fletcher and Marina (Adam Horovitz and Maria Dizzia), first-time parents doting on their infant son while they remain childless after several miscarriages.

Change comes to their lives when Jamie (Adam Driver) introduces himself as an aspiring filmmaker after one of Josh’s college lectures. Enthusing over Josh’s one completed work—which he acquired on VHS on eBay—Jamie and his girlfriend Darby (Amanda Seyfried) come to fill the void in the Svebnick’s lives, entrancing them with their devil-may-care attitudes about behavior and their retro preferences for vinyl records, typewriters and video tapes. (As Josh remarks, their apartment is filled with stuff they threw out.) Josh has soon taken Jamie under his wing, but it’s really the hip younger man who proves to be the teacher, particularly after one of his apparently off-handed ideas—to make a film about an old high school classmate named Rick (Brady Corbet) who was the first to connect with him on Facebook—turns out to be something that attracts not only financing from a hedge fund manager (Ryan Serhart) to whom Josh unsuccessfully pitches his project, but admiration from Breitbart himself.

It wouldn’t be fair to reveal too much about how this scenario works itself out: suffice it to say that what emerges is a contrast between old-fashioned idealism and a sense of canny pragmatism in the ambition to succeed. And the confrontation that occurs is one of the weaker elements of Baumbach’s script (though it does allow for a deliciously understated cap to Grodin’s performance, which overall reminds us how much of a loss his long absence from the screen has been).

But that’s not the only lapse in a generally amusing film. The attempt by Josh and Cornelia to fit into the world of their young hipster friends is often engaging, but there are points at which it devolves into material that would seem more suited to dumb studio fare. An episode in which they’re introduced to a ceremony presided over by a feel-good guru who promotes the consumption of yage for purgative purposes, for instance, is embarrassingly lame. And the finale resorts to one of the most obvious means of resolving marital difficulties—the idea that a child will inevitably lead a couple back to happiness. It’s far too easy a resolution for a picture that elsewhere is so clever and insightful.

Nonetheless despite the screenplay stumbles, Stiller puts his intense befuddlement to good use here, and the affably loose Driver and canny veteran Grodin are equally fine. Unfortunately, “While We’re Young” proves a very male-centric piece, and the female characters are underwritten, offering neither Watts nor Seyfried the chance to employ their talent to the fullest. (Indeed, Dizzia outdoes either of them with far less screen time.) On the other hand, Yarrow is a hoot, and Horowitz and Maher enjoy a few choice moments as well. In his few scenes, moreover, Serhart exhibits shrewd comic timing. The technical side is expert as well, from Sam Levy’s cinematography to the background score, which incorporates Vivaldi’s mandolin concerti, among other pieces, to excellent effect.

“While We’re Young” doesn’t always work, but it’s head and shoulders above the run-of-the-mill comedies Hollywood churns out all too regularly.