The latest Hollywood effort to capitalize on a popular toy brand is a distinct improvement over predecessors like the “Transformers” and “G.I. Joe” franchises. “The Lego Movie” is nothing if not inventive, colorful, fast-moving and, in the end, heartwarming. It’s also overstuffed, overlong and fundamentally snarky. But its fundamental approach, which both celebrates the brand and ridicules obsession about it, is a mark of how smartly constructed it is, and the wild visuals are testimony to how expertly it’s been constructed.

The screenplay by Phil Lord and Christopher Miller (from a story credited to Dan and Kevin Hageman) is essentially a “Matrix”-inspired action adventure about a happy as a clam, million-in-a-million Lego builder drone named Emmet (voiced by Chris Pratt), for whom a ditty titled “Everything Is Awesome” is an anthem. His repetitively joyous “life,” constructing edifices from blocks that are then demolished and rebuilt endlessly, is interrupted when he encounters Wildstyle *(Elizabeth Banks), a lego-ishly sultry femme who’s searching for a unique piece that will mark its discoverer as “The Special.” Or so states a prophecy made by good wizard Vitruvius (Morgan Freeman) to the villainous President Business (Will Ferrell), who intends to employ a mysterious power called Kragle to freeze the Lego universe in place forever.

It’s Emmet who finds the special brick, however, and so he’s reluctantly off with Wildstyle to defeat Lord Business’ scheme. They’re joined in their efforts by Wildstyle’s boyfriend, the egotistical, chauvinistic Lego Batman (Will Arnett), who’s one of the “Master Builders” that include other DC comic characters but also figures from “The Lord of the Rings,” the Harry Potter movies, the sports world and even the “Star Wars” franchise (which must have represented the result of some negotiation, since virtually everything else derives from the Warner Bros. stable), as well as thoroughly off-the-wall items (pirates, clowns, etc.). What follows is a series of confrontations with President Business and his chief henchman, a cop voiced by Liam Neeson who can shift from happy-face to frowning one just by turning his head. And the various stand-offs are set in Lego-land “worlds” like a Wild West saloon or “Middle Zealand.”

But one shouldn’t take the plot too seriously, because the filmmakers certainly don’t. The raucous episodes are simply a springboard for a constant barrage of extravagant visual gags, snide pop culture references, goofily slapstick action, bad puns and other assorted assaults on the funny-bone, delivered with machine-gun rapidity and force. At times the effect is joyously funny, at others simply exhausting; and one wishes that the 3D were dismissed so that the colors would blaze with greater impact and 110-minute the running-time had been trimmed a bit.

There’s also a sharp turn involving what the characters refer to as “The Man Upstairs” in the last fifteen minutes or so, when the animation gives way to live action and the picture takes on a gentler, more ruminative tone to deliver a message about embracing imagination and sharing fun rather than trying to monopolize it. The twist is actually quite affecting, but without spoiling it with too much information, it does raise questions about the supposed source of the witty, rather sophisticated material that’s preceded it.

Still, it’s ungracious to be too critical of a movie so richly creative and off-the-wall for lacking something in the way of logic. Like “Wreck-It Ralph,” “The Lego Movie” cleverly plays on the audience’s familiarity with games and toys, finding the sweet middle ground between hucksterism and spoof. Unlike “G.I. Joe” and “Transformers,” its bombast is delivered with style as well as a wink, the eye-popping images accompanied by dialogue that’s delivered in so rapid-fire a fashion that you’re likely to chuckle at a winning line before you have time to groan over the one that came immediately before it. It also boasts a first-rate bunch of voice talent, with Pratt, Banks, Ferrell and Arnett all in peak form and Freeman happily sending up his own oracular status.

“The Lego Movie” is the rare instance when what might sound like a terrible idea turns out pretty well. Even those who have never touched the little plastic blocks should find it unexpectedly enjoyable.