[Editor's note: The interview with Matt Groening took place last week, before news broke that longtime Simpsons star Harry Shearer was exiting the show.]

Springfield is getting some unexpected visitors.

Sunday's season finale of The Simpsons will feature a couch gag crossover with Adult Swim's Rick and Morty. Rick and Morty (both voiced by co-creator Justin Roiland) crash land their space ship into The Simpsons' living room, prompting Morty to go on a mission to bring the family back to life.

See more THR Behind the Scenes: The Making of 'The Simpsons'

Sunday's couch gag is a rare instance of two series owned by different studios are crossing over. Adult Swim owns and produces Rick and Morty, while 20th Century Fox owns The Simpsons. Rick and Morty, co-created by Dan Harmon, centers on an alcoholic, irritable inventor (Rick) and his anxious grandson (Morty) and their adventures together. Its second season debuts July 26.

In a conversation with The Hollywood Reporter, The Simpsons co-creator Matt Groening and Rick and Morty co-creator Roiland reveal how the collaboration came about.

What was the genesis of the couch gag?

Justin Roiland: I had the crazy idea of asking Matt and some of the folks at The Simpsons if they would be interested in doing a DVD commentary on Rick and Morty because I had heard from Mike Lazzo over at Adult Swim and a few other people that Matt was a huge fan of the show, which I couldn't believe, but it turned out to be true. That commentary track led to the offer of the couch gag, which we immediately followed up on to see if that was a sincere offer, which it was.

Matt Groening: It turns out I wasn't the only fan on The Simpsons of Rick and Morty. The animators on the show were fans and all of the writers as well. We've never done a DVD commentary for another show. We do DVD commentaries for every episode of The Simpsons, and everyone is pretty worn out. But when the opportunity came to do one for Rick and Morty, we said yes. The rest is Hollywood magic history.

Read more 'Simpsons' Showrunner on Harry Shearer: "We're Not Forcing Him Out"

Justin, what was the process like? Did you you write a script and for The Simpsons folks to approve?

Roiland: Dan Harmon did the first pass on the script, and then we were in the thick of it on writing the season two stuff and he got swept away on Community. So I took the script and polished it, changed a few things. Then we sent the script off to Al [Jean] and Matt and everyone at The Simpsons. It was incredibly, creatively free. I don't think we got a single note from you guys.

Groening: We loved it. We have this section of the show called The Couch Gag where we break all the rules of animation that we have on The Simpsons, so it's all surrealistic and crazy. Over the last several years, we've decided: let's have other animators take on The Simpsons, and Justin and Dan's takes with Rick and Morty visiting The Simpsons was probably the most ambitious and lengthy couch gag that we'd done.

Roiland: I didn't want to overstay our welcome so I tried to make it tight and quick. Originally, I wanted it to hit around 1:30 but then it just kept creeping and creeping. I did suck a lot of time out of it, believe it or not.

Groening: I loved it. You certainly can't see where it's going, except you might think something bad might happen to The Simpsons. It plays like a mini-episode. What really makes me happy is to think of the die-hard fans of Rick and Morty tuning in and having their minds blown. It really is an extension of your cartoon universe, and that we're part of it is really cool.

Roiland: We tried to pull in stuff from Futurama and little Easter egg stuff. It's also the first thing anyone has seen of Rick and Morty since season one finished, which is really cool.

Groening: So where are you on season two?

Roiland: I'm actually posting 206. And then we've got seven, eight, nine and ten are still being animated in Bardel [Entertainment] in Canada. So we're past the curve. We're getting close.

Groening: You guys really did it great. We have had such great luck with our guest animators. We've had Bill Plympton, John Kricfalusi, the creator of Ren and Stimpy. Guillermo Del Toro storyboarded a Halloween episode sequence. Probably one of the wildest things we've ever done in the history of the series is one by Banksy, which ends with the 20th Century Fox logo as a giant prison camp, apparently. So Justin, you guys are in really good company, and you really delivered.

How did it work being at different studios?

Roiland: We took care of our side here. We got some assets provided to us from [animation studio Film] Roman. Then we stumbled to put everything together on our side, then all the sound effects mix was done over on The Simpsons side. It's pretty much left to the animator to put together the gag and see it through, and you basically deliver a fairly finished piece they plug into the show and mix into the show.

Groening: One of the most remarkable things is the fact that you do the voices of both Rick and Morty. That's pretty amazing. On The Simpsons we have actors who play against themselves as multiple characters, but that's basically your whole show. Do you record separately or do you go back and forth?

Roiland: I go back and forth a lot, but I still will go in and record as scripted separately. But I do love to go in and run scenes and go off script. That's something I did on the couch gag for sure. I went in and threw out certain pitches. The characters seem to come alive a little more when I do that, when I bounce between the two of them. I have a dyslexic mind, so certain words come out in the wrong order or in a really weird, oddly specific way that works really great for the characters, that is almost impossible to script.

The Simpsons airs Sundays at 8 p.m. on Fox. Rick and Morty returns for season two on Adult Swim July 26.