Cowboys trained in martial arts battle the Law — in space? That’s the far-out premise of Joss Whedon’s frequently silly, yet always entertaining futuristic western “Serenity.” Resurrecting his short-lived television series “Firefly” in full-length movie format, “Buffy” creator Whedon brews up a sci-fi epic that is refreshingly free of the bad taste left by recent “Star Wars” endeavors.

The film is not perfect by any means. The plot is barely present except during the marvelous beginning, and the writing is too clever for its own good. Whedon’s characters have a penchant for chatting it up, skirting the emotional truth needed in a story heavily concerned with issues of life and death. But when “Serenity” succeeds, its quirky blend of genres and cliches produces one hell of a ride.

Fast-forward five hundred years in the future. Earth has been forgotten as the human race moves out into the universe and colonizes an entire galaxy of planets under an expansive umbrella government, which exists to protect its citizens (or that’s what PR men of the future want you to believe.) In actuality, the Universal Alliance is hiding a dirty little secret that could bring down its administration if it were to fall into the wrong hands. In this case, those dextrous hands belong to River (Summer Glau), a mentally disturbed psychic trained by the Alliance as a weapon. Resistant to their mind control techniques, she escapes — accompanied by crass explosions — from their clutches with the help of her brother Simon (Sean Maher).

Now hiding out on the Serenity, a stagecoach of a ship piloted by the lawless, yet kindhearted, Mal (Nathan Fillion) and his wisecracking crew, River must recall information about a crucial government cover-up before a ruthless assassin (Chitwetel Ejiofor) picks her mind first.

“Serenity” moves through its paces with the graceless efficiency of a TV show. The acting is, to put it bluntly, mostly horrendous. And although bad makeup, hair and sets are relatively unnoticeable on small television screens, they appear blatantly amateur in cineplex scale.

But rather than downplaying these melodramatic aspects of his space-age soap opera, Whedon delights in their artificiality. Lines are hammed up beyond belief, zombies somehow make their way into space, and yet despite the film’s sheer ridiculousness — or perhaps due directly to it — “Serenity” becomes a rip-roaring good time.

Whedon manages to throw together a pastiche of bad dialogue from all sorts of movie genres and make the lines fresh and funny again. Harkening back to the glory days of “Indiana Jones,” Whedon is an expert at taking a scene along a predictable course only to pull the rug out from under it at the last minute.

The crew interactions are also quite funny, if not entirely believable. Whedon works from a toolbox of pre-assembled caricatures, but adds enough quirks to keep the banter enjoyable. At several points characters seem to become Whedon himself, pointing out flaws in the screenplay with the noxious tone of writers in a round table rewrite session.

Yet the film’s main problem lies in its bloated irreverence. Nearly a self-satire, it invokes serious themes only to scoff at them as cliches. “Serenity” loves to point out that you are, in fact, watching a movie. While this is all very post-modern and ironic, it blunts any emotional investment in the characters or their fates.

Only River seems to take herself seriously. Moving with the grace of an otherworldly contortionist, she’s like a ghost on loan from the latest high-art horror flick.

Whedon would like you to take other things seriously as well. Several villages are massacred over the course of the film. In one, the camera lingers on a small child, begging for sympathy. But these scenes simply point out the discrepancy between the film’s brilliant comedy and its absent tragedy.

Just when “Serenity” looks lost in emotional limbo, the last act kicks in and saves the day. Whedon’s writing finally comes into its own and characters start to mean something. The excess dialogue dries up as the ship’s crew moves away from prescribing emotions. Instead of indulging in detachment, Whedon ultimately risks naked vulnerability.

Once “Serenity” stops trying to convince us it has a brain, we can finally hear the sound of its katana-wielding heart.