LOS ANGELES (AP) — When director Peter Farrelly set out to make what became the genre-defining rom-com “There’s Something About Mary” more than 25 years ago with his brother, Bobby, he knew it might take some convincing for a studio to open the purse strings for a boundary-pushing comedy.

“People are scared to do comedy,” the Oscar winner recalled. “We were lucky because there hadn’t been a lot of R-rated comedies in quite a few years. Most of them were PG-13.”

And while its box office debut was rocky, it ultimately became the third highest-grossing film in the year it was released.

Now, Farrelly is banking on that same thirst for vulgarity and depraved humor for “Ricky Stanicky,” his latest buddy comedy starring Zac Efron and John Cena that hits Prime Video on Thursday.

The film’s script sat in limbo for more than a decade with a host of big names, including James Franco and Jim Carrey, attached to it at various points.

And while the powers that be in Hollywood expressed reservations about making something that skewers certain stereotypes — like millennial parents and method actors — and is saturated with sex and drug humor, Farrelly is confident he is satiating an appetite.

“People were afraid to make it for a long time. But audiences are dying for that kind of comedy,” he said.

Part of those anxieties stemmed from an uncertainty about what is too far and what is off limits, a tension some comedians have voiced frustration about in recent years.

“All of the things that have happened in the last five, seven years that have scared people off of comedy are for good reason. These are good changes,” Farrelly said. “I think about it all the time. But I believe that if your heart’s in the right place and the characters’ hearts are in the right place, then you can get away with murder.”

“Ricky Stanicky” follows four childhood friends — well three and one imaginary one. For 20 years, the trio has been relying on a made-up friend named Ricky Stanicky whom the boys use to get out of trouble, obligations and even romantic relationships that aren’t going well.

But as the responsibilities of adulthood risk exposing them being caught in their lie, Dean (Efron) has the idea to hire an actor (Cena) to play their imaginary friend and assuage any doubts their loved ones have of his existence.

Efron grew up loving Farrelly’s films. Although “Dumb and Dumber” has always been the actor’s favorite, he said “There’s Something About Mary” is a “really close” second.

More than just a fan though, Efron had already worked with and developed an appreciation for the director when he starred alongside Russell Crowe in Farrelly’s 2022 film, “The Greatest Beer Run Ever.”

“He cuts through all the pipes and he’s just a great partner to work with. He always tells you honestly how he’s feeling and keeps you on track. I think that’s what I value,” Efron said. “There’s a lot of hilarious circumstances that the characters encounter over the course of the film, but it stays rooted in heart and love. And I think that’s just Pete.”

Efron, who had just finished making his physically and emotionally draining indie drama “The Iron Claw,” said filming for this project came at the perfect time. “It was exactly what I needed. I needed to just laugh and have fun,” he said.

Krysta Fauria, The Associated Press