Thomas Dekker has been acting since he was six years old. Now 34, he’s best known for playing Zach on “Heroes” and John Connor on the short-lived “Terminator: The Sarah Connor Chronicles.”

But the spotlight unexpectedly became much brighter in 2017 when former “Heroes” co-executive producer and writer Bryan Fuller outed Dekker during a speech at Outfest. While Fuller didn’t mention Dekker by name, he talked about a gay actor on the show whose character was also gay until the actor’s team insisted he be straight. It didn’t take long for people to figure out who he was referring to.

Dekker responded by acknowledging he was gay in an open letter he posted on Twitter.

Looking back, Dekker insists he has no hard feelings toward Fuller. “Everyone has their journey and I hated that mine was taken away from me in a way,” Dekker tells me during a recent Zoom interview from the Los Angeles home he shares with his husband of five years, actor Jesse Haddock. “But it was also this kind of a weird fucked up blessing because it opened the door for me to just be fully who I am.”

Dekker, who stars as out Hollywood studio executive assistant Travis in Roku’s new series “Swimming With Sharks,” gives his first interview about being outed, his battle with alcoholism and the piece of advice he received from Natasha Lyonne that he will never forget.

Travis is your first gay role since coming out as gay. How is it different this time around?

I played bisexual, gay, you name it; multiple times, but this is really kind of my first thing as an out actor. It’s a world of difference. I think, first of all, just by virtue of being out, I am healthier and able to do what I do the way I do it in a more effective, consistent way. I was in a weird era where it was a career-killer to be gay, but it was a career asset to play gay. So here I was 22 at Cannes in 2010 promoting my Gregg Araki sex movie, “Kaboom,” but God forbid anybody knew I liked men. Fortunately, the world has changed so much in the last 10 years in the industry as far as acceptance and inclusion.

When you were playing gay roles before, was there a part of you that was scared you’d be found out?

It was very much about that. Crazy shit happened when I was 19. I remember being on a certain TV show for a network and I was called into a board meeting with the heads of the network to basically very gently say to me, “We don’t want you to confuse the audience. We want to make sure that you don’t get in the way of this role.” It was a very veiled way of saying, “Stay in the closet.” Today feels like a whole new world to be out. I feel free.

What did you think when you first heard what Bryan said about you at Outfest?

Bryan and I had not had any contact of any kind since doing “Heroes” 11 years before. I was 29 at the time and I had just gotten married in secret — not secret from my circle and my friends and who I was close with, but secret from the public. I was still under the sort of spell of, “Oh, Jesus. If my truth comes out, it’s all over. It’s kiss the career goodbye.” I sort of had that drilled in me for so long and it was [my publicist] who called me and he said, “Listen, there’s a situation you’ve been basically, not by name, but you’ve been outed in an Outfest acceptance speech.” Then everybody said, “You can say nothing and let this kind of die down or you can take this opportunity and come out.” It was kind of a weird fucked up blessing because it opened the door for me to just be fully myself.

So let’s talk about your sobriety. You’ve been sober for four years?

It was precisely one year after being outed, four months into being 30, one year into marriage. My sobriety birthday is just two days after my wedding anniversary. I haven’t spoken about it before, but I want to speak openly about it because I think this is a rather common situation. I did a bit of everything, but my vice was alcohol. It was hardcore alcohol.

How did you get sober?

I started in Alcoholics Anonymous. I’d been in those rooms with friends of mine for their sobriety. This was in early 20s. So I had knowledge of it and that was good because it made it way less intimidating. When the day came, it was like I know what this is, but I also had numerous friends of mine and people I’d worked with and my own spouse who had come to me and said, “This is a problem.” [Dekker was sentenced to a fine of $300 and two years of informal probation, and ordered to attend a 12-hour alcohol-education class in 2009 after being charged with a DUI in North Hollywood].

So what’s next for you?

I have a film that I’m looking to make next, which is an unapologetically gay genre mind-bender. It really hasn’t been done before.

Will you star in it, direct, produce?

Not the star in, but I’m writing it and I’ll direct. We’re in the process of getting that off the ground right now. And I’ll tell you, every time I have a meeting about this film, the verbiage is always, “It’s just really hard to get a film of this size made.” It’s a relatively small film, but they always say that a film of this size that is a genre film, a film with a fully gay character lead is impossible to get made. And my response every time is, “Okay, then we’ll be the first.” I’m not going to be deterred because it hasn’t been done before. The most beloved piece of advice that I ever got that I was not prepared to hear at the time was from Natasha Lyonne in 2011. I had been John Connor on the “Terminator” show, which was kind of the pinnacle of young masculinity. And then I’d done a kind of slew of indies I wanted to do. Then I got another CW show, where I was going to be the leading man again and she found out about it and we were on the phone and she said, “There’s so much to you that makes you so special. I’m not quite sure why you and your team are consistently putting all that over here and trying to kind of put you in this vehicle that isn’t you.” I knew she was right because she really knew me. She could see kind of the closet doors just weighing on me. I didn’t take that advice then, but I think once I was out, I was able to follow it.

This interview has been edited and condensed for length and clarity.