Sarah Hyland opened up about her battle with depression while going through a series of health issues including undergoing two kidney transplants.

The "Modern Family" actress spoke to Ellen Degeneres Friday where she said she struggled with suicidal thoughts after "years of just always being sick."

"After 26/27 years of just always being sick and being in chronic pain every single day and you don’t know when you’re going to have the next good day, it’s really, really hard," Hyland told DeGeneres. "I would write letters in my head to loved ones of why I did it and my reasoning behind it, how it was nobody’s fault. I didn’t want to write it down on paper because I didn’t want anybody to find it. That’s how serious I was."

Hyland, 28, said she was "very, very, very close" to taking her own life.

SARAH HYLAND REVEALS SHE HAD A SECOND KIDNEY TRANSPLANT

"It ended up being myself that got me out of that," the actress shared. "I had to do it on my own. I told myself I had to do it on my own."

Hyland said she finally decided to get help after opening up to a friend about her depression.

"Just saying it out loud helped immensely because I kept it to myself for months and months at a time,” Hyland said. "I didn’t want anybody to know that I was that close, because if they knew they would try to persuade me.”

The actress warned that while sharing her thoughts with friends is what helped her get better she doesn't want to speak for everyone who struggles with depression.

"Every person with their anxiety or depression or if you have suicidal thoughts, every individual is different, so I wouldn’t just rely on everything that I say,” she noted. "I’m just sharing my story. But I think talking to someone and saying it out loud really, really makes it sound almost ridiculous and it puts it into perspective."

'MODERN FAMILY' STAR SARAH HYLAND SHOWS OFF KIDNEY TRANSPLANT SCARS IN BIKINI SELFIE

Hyland revealed in a wide-ranging interview with Self in December that she underwent a second kidney transplant after receiving a kidney from her father in 2012. It was previously made public that she lives with kidney dysplasia, which essentially means her kidneys did not form correctly when she was in the womb.

Hyland told the magazine she doesn’t know why the organ gifted to her by her father didn’t take properly.

“When a family member gives you a second chance at life and it fails, it almost feels like it’s your fault… and it’s not. But it does,” she said. “We did all of these tests and all of these treatments to try and save the kidney, but they basically said the transplanted kidney was like a house that caught on fire, you can’t un-burn a house.”

CLICK HERE TO GET THE FOX NEWS APP

Fortunately, Hyland learned that her younger brother was a match and was willing to give his kidney to her in a second attempt to correct her failing health.