One feels a bit of both desperation and liberation in M. Night Shyamalan’s latest, a bizarre horror comedy that forgoes the mystery-with-twist-ending template that marked his work, like an increasingly heavy albatross, from the brilliant “The Sixth Sense” to the laughable “The Village,” and thus must have brought a feeling of freedom. But on the other hand “The Visit” represents yet another step in the search for a different genre that Shyamalan’s struggled with ever since—the goofy fantasy “Lady in the Water,” the prosaic sci-fi “The Happening,” the misguided family flick “The Last Airbender” and the awful futuristic actioner “After Earth”—and so seems almost an act of desperation. Working with a budget that must have been his tiniest since “Sense,” he’s fashioned a weird, sporadically amusing trifle that blends elements from some of his earlier pictures with a ghoulish sense of humor—something in the style of Joe Dante—and serves it up in the increasingly musty found-footage format. The result will appeal to fans of creepily oddball horror flicks like Bob Balaban’s “Parents” (1989) but probably not to general audiences, who are likely to be turned off by its combination of ponderousness (a Shyamalan trademark) and sheer off-the-wall nuttiness.

Shyamalan’s screenplay is a variant of the Hansel and Gretel story—a point emphasized by the attention given to an industrial-sized oven in several kitchen scenes; but it also recalls Peter Rader’s little-seen thriller “Grandmother’s House” (1988), though with a smirk. The Philadelphia brother-and-sister duo of fifteen-year old Becca (Olivia DeJonge) and thirteen-year old Tyler (Ed Oxenbould) travel for a weeklong stay to the farm of their grandparents Nana (Deanna Dunagan) and Pop Pop (Peter McRobbie), whom they’ve never met; the old couple have been estranged from their daughter (Kathryn Hahn) since she left the nest in anger some two decades earlier, but they’ve reached out now to meet the grandkids, and since Mom’s been invited to go on a cruise with her new boyfriend, she agrees to the visit—albeit with misgivings.

Once ensconced on the farm, the precocious youngsters—who, of course, are filming everything (Becca being an aspiring moviemaker and Tyler a little would-be rapper who loves being on camera)—quickly discover that their grandparents are pretty weird. Nana loves to cook, but she has a habit of wandering around the house at night nude, scraping at doors and walls like a wild beast. Pop Pop is hoarding some very strange stuff in his shed, and regularly dressing up for a costume party that doesn’t exist. Their moods change radically from moment to moment, careening from nurturing to threatening at the drop of a hat. And what of the warnings that the kids shouldn’t leave their room after 9:30, or ever go down to the basement? It’s no wonder that before long the kids are skyping their mother with worried looks on their faces.

Shyamalan springs a surprise about why the grandparents are so strange, but unlike in “The Sixth Sense” or even “Unbreakable,” it’s not much of a surprise—the fact that the few people who come to visit the couple have peculiar reasons for doing so and always happen by when they’re conveniently off for a walk is pretty much a dead giveaway—and he doesn’t wait until the finale to reveal it. Like Hitchcock in “Vertigo,” he tells us what’s going on long before the end, but unlike in that masterpiece after doing so he has nowhere to go except to stage a raucous half-hour of what amounts to child endangerment (an important element of which has been foretold in a crushingly obvious fashion in a childhood reminiscence Tyler speaks into Becca’s camera). Not that he’s managed to tightened the screws very effectively even before that. Nana and Pop Pop are cartoonish figures from the moment they first appear onscreen, and merely grow more so as the story progresses. Both Dunagan and McRobbie play them to the hilt, but they never become anything more than figures from a carnival house of horrors. On the other hand, Hahn opts for realistic sincerity, and overdoes it badly.

The youngsters offer some compensation, though their smug articulateness can be annoying. DeJonge is fine, but it’s Oxenbould who’s the sparkplug of the duo, and it’s hard not to like the quirky little guy even when he’s handed grating material. (At one point he has to toss a ball up in the air and try to catch it in order to mislead Nana and Pop Pop into thinking he’s having fun, and to explain to Becca, “This is how children are supposed to play.” And though his rap routines might amuse many viewers, they’re actually a fairly cheap ploy.) One also has to praise the cinematography of Marysi Alberti, who’s pretty cagey—at least until the final half-hour or so—in mitigating the effect of the found footage technique, which would surely have been retired by now if it didn’t keep budgets down. The other technical aspects of the picture are above average for the genre.

But as Tyler opines to Becca when they disagree over whether to try to document Nana’s nocturnal wandering with a hidden camera, “Nobody gives a crap about cinematic standards.” So despite its technical polish, the fact is that “The Visit” isn’t the movie that’s going to refurbish Shyamalan’s star—it’s a muddled attempt to meld comedy and horror that doesn’t succeed especially well as either. It’s also the writer-director’s best movie in years, but that’s faint praise indeed.