The latest feature from DreamWorks Animation is a triumph and a delight for audiences of all ages.

Nicholas Stoller has been mixing it up between raunchy R-rated comedies (he’s the director of Neighbors and its sequel and co-writer of Sex Tape) and family films (as co-writer of The Muppets and Storks), but he’s finally found the sweet spot that links his best work and talents together with his screenplay for Captain Underpants: The Epic First Movie.

Based on the best-selling children’s novels by Dav Pilkey, the animated movie is a smorgasbord of kid-friendly potty humor — literally it involves a giant toilet robot and a villain named Professor Poopypants — and may turn out to be one of the best superhero movies of the year. And from the look of things so far, that’s a pretty big feat.

Captain Underpants is the story of best friends George (voiced by Kevin Hart) and Harold (Thomas Middleditch), fourth grade pranksters stuck in an Elementary School void of fun, joy, and arts programs. Ruling over the miserable institution is no-nonsense Principal Krupp (Ed Helms), who threatens to separate the boys and drive them apart.

In addition to their practical jokes, which are presented in a wonderful montage, George and Harold also create comic books starring their satirical hero, Captain Underpants (most superheroes look like they’re wearing underwear, so theirs literally wears just white briefs and a cape). One day they mean to pretend to hypnotize Krupp with a toy ring from a cereal box, but it works. So, they decide to make him think he’s their superhero.

A lot of comedy, much of it cartoon slapstick, ensues because Krupp as Captain Underpants believes he’s truly a hero with super powers. He’s like Buzz Lightyear through much of the first Toy Story movie. But the dominating humor comes from a place of innocent immaturity. Not just in the basics of silliness and grossness but in the embrace and appreciation of children’s amusement with such things.

There’s significance, for instance, in the bond between George and Harold having been forged through their response to the name of the planet Uranus. It’s not that the movie’s audience is expected to laugh at its utterance, or at the name Poopypants, though many young moviegoers will, so much as understand why such names are funny to little kids. And through that understanding laugh along and enjoy the silliness with the characters.

For his part, Stoller continues to prove himself an expert in how comedy works, for all types and ages and senses of humor, and that really shows in this celebration of potty humor. Yet while there is some meta quality to the movie, enough that we could argue that it’s a movie written by George and Harold adapted from their own comic (it’s like Adaptation Jr.), Captain Underpants isn’t all that deconstructive.

Stoller, who believes that fart jokes, like all comedy, should come from character, keeps the story character-driven, which is why the juvenile stuff works, always through the kids’ point of view. Stoller also believes we live in an R-rated world and makes adult comedy with that in mind, but this is his first children’s film recognizing that kids live or see things through an infantilized PG version of that R-rated world.

Credit should also go to the movie’s director, David Soren, who also contributed to the final script and who voices one of the minor characters. It’s unclear what of the writing is his, but if Stoller’s effort is the foundation for why Captain Underpants is a hilarious success, Soren is the one who carries forth that brilliance in a vibrant and charmingly performed animated feature that’s better than pretty much everything else he’s worked on, including his only past feature as director, Turbo.

The visuals of Captain Underpants are mostly just three-dimensional renderings of Pilkey’s drawings, similar in form to the computer-animated versions of Charlie Brown and friends seen in Paul Feig and Steve Martino’s The Peanuts Movie. There are some variations, though, with clever segments using 2D animation when showcasing George and Harold’s comic stories, sock puppets for a nightmare sequence, and subtle collage inserts in various moments.

There are fresh ideas around every bend of this movie, maintaining more depth in storytelling and direction than you could ask for with something sourced from a series of kids’ books involving childish things. I haven’t been this surprisingly delighted with an animated feature I’d been skeptical about since Cloudy with a Chance of Meatballs.

A lot of kids’ movies these days are just immature and gross to be immature and gross without any basis in story or character or understanding of why they should land with young audiences. Captain Underpants triumphantly honors children’s humor, creativity, friendship, love of superheroes, love of poop jokes, and more with brains and heart and guts.