Sometimes, no matter how good a role is and how much you want it, family has to come first.

That’s exactly what happened to John C. McGinley, the star of the new IFC series “Stan Against Evil.”

The actor, most famous for his role as Dr. Perry Cox on the much loved comedy series “Scrubs,” was being courted for the leading role in the new horror/comedy hybrid, except it conflicted with a long-running McGinley family tradition.

More than 15 years ago, the actor, his two brothers and their dad took a trip out to Ireland “to play golf and lie about how great we used to be, honestly.”

But then 9/11 hit, and McGinley’s brother Mark was on the 63rd floor of the second building. He made it out safely, though he had a concussion and was missing for 12 hours.

“When Mark did finally surface, one of the takeaways was, ‘Damn it, when we say we’re going to do something as a family, we’ll goddamn well do it,’’’ McGinley says. “We haven’t missed a year since. Dad passed a couple years ago and we filled his spot with one of our cousins.”

So how does that story tie in with a series about a former sheriff who loses his wife and has to fight demons and monsters in his small town?

“That’s a long-winded way of saying when ‘Stan’ was offered to me ... that was the week we were going to go to Dublin.”

McGinley’s proposal: delay the production a few weeks and he’s game for the series, which he called “the funniest thing I’ve ever read.”

“They took a couple of days, and I was sweating it pretty bad because I really wanted to play Stan, and then they said, ‘Yeah, we’ll move the production.’

“I said, ‘Guess what? Now I’m going to eat [expletive] nails for you people. If you accommodate something that has to do with me and my brothers, I’ll run through drywall for you,’” he says.

And McGinley put a lot of that aggressiveness into his interpretation of Stan, who begins the series with the death of his wife of 30 years and the loss of his job of nearly as long.

“This guy is injured,” McGinley says. “And he doesn’t have a priest or rabbi or a shrink that he can go to. It’s called loss reconciliation and he doesn’t have any of those tools, and — because he’s cut from the Archie Bunker archetype — even if he had those tools, he wouldn’t use them.”

Stan, much like the patriarch at the heart of the classic sitcom “All in the Family,” is an old-fashioned guy with old-fashioned perceptions on life.

“The way into Stan was through his dead wife, just like the way into Archie is Edith,” he explains. “Unless Edith’s love for Archie is indefatigable, Archie’s just a [expletive]. And he’s not.

“So when Archie and Stan are equal opportunity disparagers, it has to be at their expense and not ours,” McGinley continues. “And if it’s at their expense, Archie’s and Stan’s, then we got a guy that we can cheer for, because he’s an emotional cripple.”

Also essential to this series it the tone, which has to balance comedy and horror, a difficult feat.

“[Creator] Dana [Gould] and I were obsessed with the tone,” he says. “And so we had all of the actors playing this thing straight up. There’s a very glib, kind of sardonic way ... we just impressed upon them that we didn’t want them doing ‘Scooby Doo.’”