Thomas Middleditch has walked his fair share of red carpets as the star of HBO’s “Silicon Valley,” so the man knew how to make an entrance Sunday morning at the premiere of DreamWorks Animation’s “Captain Underpants.”

In a nod to the title, the actor wore a pair of tighty-whities over his suit, which he explained was perfectly in keeping with the franchise’s hero. “Captain Underpants is such a lovable, positive character,” he said of this adaptation of the Dav Pilkey hit series of children’s books.

However, Middleditch isn’t the actor who voices Captain Underpants (he plays sidekick Harold Hutchins); that falls on the shoulders of Ed Helms, who joked that the part was tailor-made for him.

“Captain Underpants is the closet character to myself I’ve ever played,” he said. “I just hope the fans of the book think this is a faithful adaption.”

According to producers Mireille Soria and Mark Swift, what attracted Dreamworks Animation to “Captain Underpants” — the last title 20th Century Fox will be distributing before Universal Pictures takes over release duties — was the character’s resonance with young audiences, and parents.

“I would read this with my kids and it would be just laugh-out-loud funny,” Swift said. “We think we’ve brought the incredible originality of the books to the big screen.”

“Captain Underpants” opens in theaters June 2.

Universal Filmed Entertainment Group chairman Jeff Shell, president of DreamWorks Feature Animation Group Christopher DeFaria and actor Thomas Middleditch. Cook/Variety/REX/Shutterstock

(Pictured above: Stars Nick Kroll, Ed Helms, Kevin Hart, Kristen Schaal and Thomas Middleditch’ flank producer Dav Pilkey)