Sarah Hyland is best known for portraying Haley Dunphy on the ABC sitcom "Modern Family." Jordan Strauss/Invision/AP

Sarah Hyland recently discussed her chronic health problems during an interview with Ellen DeGeneres.

Hyland revealed that when she was 26, when her body began to reject her first kidney transplant, she seriously considered suicide.

"I was very, very, very close," Hyland told DeGeneres. "I would write letters in my head to loved ones - of why I did it, my reasoning behind it, how it's nobody's fault. And I didn't want to write it down on paper because I didn't want anyone to find it."

The "Modern Family" star recently had her second kidney transplant.

Sarah Hyland recently discussed her health - both physical and mental - during an interview with Ellen DeGeneres.

Hyland has been open about her experiences with chronic pain, resulting in 16 surgeries throughout her life and, most recently, her second kidney transplant. Hyland revealed to DeGeneres how, two years ago, her physical problems manifested in depression and suicidal thoughts.

"I would write letters in my head to loved ones - of why I did it, my reasoning behind it, how it's nobody's fault," Hyland told DeGeneres. "And I didn't want to write it down on paper because I didn't want anyone to find it, 'cause that's how serious I was."

"I was very, very, very, very close [to suicide]," she said. "I didn't want anybody to know I was that close because if they knew, they would try and persuade me," she said.

During this time, Hyland told DeGeneres, her body began rejecting her first kidney transplant and she was forced to go on dialysis.

The 28-year-old actress was born with a disease called kidney dysplasia, which means that one or both of her kidneys "do not develop normally while in the womb," according to the National Institute of Diabetes and Digestive and Kidney Diseases.

Hyland also has endometriosis, an incurable reproductive disorder, and while on dialysis she also developed Gout, a form of arthritis.

"I've been through a lot of pain," she said. "[Gout is] one of the most painful things I've ever had."

Read more: 9 answers to the most common questions about endometriosis that you were too scared to ask

"I have an amazing job, an amazing support system. But after - at the time, I was 26 - 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," she explained.

Hyland said what finally helped her deal with her depression was telling a friend.

"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 - I'm just sharing my story," she said. "But I think talking to someone and saying it out loud really, really makes it sound almost ridiculous and it puts everything into perspective."

Visit INSIDER's homepage for more.

NOW WATCH: Popular Videos from Insider Inc.