TV

Why ‘Modern Family’ made Nathan Fillion nervous

ABC’s surprise cancellation of “Castle” last May means that for the first time in nearly a decade, Nathan Fillion isn’t spending most days this fall on a soundstage.

But he’s back on ABC nonetheless, guest-starring in several episodes of “Modern Family” (Wednesdays at 9 p.m.) as aptly named weatherman Rainer Shine.

Fillion made his debut last week; in the episode, Phil Dunphy (Ty Burrell) appears in a real estate segment for the local news, where he gets the chance to meet and befriend his weatherman hero. But things get a little too friendly when Phil’s actions unwittingly cause Rainer to ask his 20-something daughter, Hayley (played by 25-year-old Sarah Hyland), out on a date — and Phil flips when he finds the two kissing on his front porch.

“He is shocked and horrified but the reality is he kind of set us up accidentally,” Fillion, 45, tells The Post. “He hates it but it’s also all his fault.”

By the end of the episode, Phil gets over their 20-plus-year age difference and acquiesces that his daughter is old enough to date whomever she wants, paving the way for Rainer to stick around as a new friend for the elder Dunphy and love interest for Hayley.

Fillion is set to appear in at least three episodes (the next airing in November), with the potential for two more. And after eight seasons starring as jerky mystery novelist Richard Castle, the actor jumped at the chance to play the cocky Rainer Shine when “Modern Family” producers called him over the summer to offer him a guest role.

“It’s kind of a niche for me to play characters who are vain but don’t know that they’re vain. It’s something I’m practiced at,” he says. “It’s very easy to laugh at a character who’s that stupid. He’s kind, he’s nice, he’s sort of charming, but he’s just so cheesy and so flawed.”

Fillion with co-star Stana Katic in “Castle.”ABC/Byron Cohen

Fillion, a big fan of “Modern Family,” admits he was uncharacteristically nervous coming into a successful show where he admired all the actors. While he expected to be filming Season 9 of “Castle” at this point in time, he now seems to have accepted its untimely fate.

“It wasn’t the beautiful send-off that I think maybe you could hope for, but it’s the entertainment industry, it’s a business, I get it,” Fillion says. “I don’t take it personally when a show gets canceled — I can’t take it personally, all my shows gets canceled! Look at my resume, it’s a long list of canceled TV shows.

“The fact is, I made a lot of great friends on a really great show. I’m really happy for everything that that show has done for me.”

The show’s ending has also freed up his schedule. Fillion recently traveled to Berlin and Russia and says he’d love to guest star in more TV shows — though he admits he’s probably not tough enough to appear in one of his favorites, “The Walking Dead.”

“I could always be a zombie. Of all the TV shows I watch, I think that’s the one where they suffer the most for their art,” he says. “That’s not easy to do in Atlanta. Just the weather there alone is such an insurmountable challenge. Those guys work really, really hard.”

Phil (Ty Burrell, right) gets chummy over beer with Rainer Shine (Nathan Fillion).ABC/Ron Tom