How did Pixar’s beloved “Toy Story” children’s movies lead to the foul-mouthed, sexually explicit comedy “Sausage Party,” from the screenwriting team of Seth Rogen and Evan Goldberg?

“We’re both crazy about ‘Toy Story,’ and we talked about it all the time as the only comedic trilogy that gets better with each movie,” Mr. Goldberg said in a phone interview. Mr. Rogen added: “We became obsessed with these Pixar movies. Their quality, tone and style were so much fun that we thought we should try to make one of those.”

Their animated tale, however, is decidedly R-rated, much like their comedic take on the apocalypse (“This Is the End”) or high school (“Superbad”). “Sausage Party” (in theaters Aug. 12), which they wrote with Kyle Hunter and Ariel Shaffir, is the story of a supermarket hot dog who leads other products on a quest to understand the true nature of their fate when they leave the store — they will be sliced, diced and devoured by humans. Mr. Rogen voices Frank, the hot dog, and Kristen Wiig plays his love interest, Brenda, a bun. Much double (and sometimes single) entendre humor ensues.

Animated movies for adults have a long history, including the first X-rated one, “Fritz the Cat” (1972); the sci-fi fantasy anthology “Heavy Metal” (1981); and last year’s existential “Anomalisa.” But they don’t come around often, and big-budget, computer-animated films of the DreamWorks Animation and Pixar ilk have yet to venture into R-rated territory. For this reason, Mr. Rogen and Mr. Goldberg were intent on “Sausage Party” having the professional quality and detailed sheen of the best computer animation.