She was also dealing with a hernia and an endometriosis flare.

Photo: Rodin Eckenroth/GettyImages

Sarah Hyland revealed that she had a second kidney transplant after her first one failed, leading to mental health struggles that had her "contemplating suicide."

The Modern Family star, 28, has kidney dysplasia-which means her kidneys did not develop properly when she was in the womb and frequently form painful cysts-and the condition required a kidney transplant in 2012. Her father donated his kidney, but in Oct. 2016, her body started to reject it.

"We did all of these tests and all of these treatments to try and save the kidney," Hyland told SELF for their latest digital cover. "Christmas break, New Year's, Thanksgiving, my birthday, all of that spent in the hospital."

But none of the treatments worked, and Hyland's doctor said the kidney was like a burning house-it was already too far gone. "You can't un-burn a house," she said. (Related: Sarah Hyland Says She Was Sexually Assaulted by a Friend in High School)

Hyland started regularly undergoing dialysis-a temporary treatment where a machine filters blood in and out, which is typically the kidney's job-that required putting a tube on her chest and led her to severely drop weight. On top of the health problems, she started dealing with criticism over her appearance on social media.

Doctors removed the transplanted kidney in May 2017, and her younger brother Ian, 23, offered his kidney, which was thankfully a match. But Hyland felt conflicted. (Related: Selena Gomez Opens Up About Her 5-Year Struggle With Depression)

"I was very depressed," she said. "When a family member gives you a second chance at life, and it fails, it almost feels like it's your fault. It's not. But it does. For a long time, I was contemplating suicide, because I didn't want to fail my little brother like I failed my dad."

Hyland started reaching out and talked someone close to her about her suicidal thoughts, which helped, she said.

"It's not shameful," she says. "For anybody that wants to reach out to somebody but doesn't really know how because they're too proud or they think that they'll be looked upon as weak, it's not a shameful thing to say. It's not a shameful thing to share." (Related: Michael Phelps Opens Up About His Battle With Depression and Suicidal Thoughts)

And in Sept. 2017, she underwent the second kidney transplant. But her health problems didn't end there-Hyland also has endometriosis, and the pain was becoming unbearable. Plus, she had a previously undiagnosed abdominal hernia.

"I was still in severe pain after the transplant, and that was due to the endo and the hernia," she said.

That led to more surgeries-she's had six in the last 16 months, and 16 total over the course of her life-a laparoscopic surgery for the endometriosis and a hernia repair surgery.

"Laparoscopic [surgery is] one of the most painful things I've ever been through in my life," she said. And the endometriosis pain doesn't really go away. "[This week] I've had a flare-up with my endo. It has been hard to stand up straight, let alone work. The fetal position helps a lot."

But the support of her family, (most) of her followers on social media and her boyfriend, Wells Adams, help Hyland manage her health. She and Adams first met three days before her transplant surgery, and they fell in love as she underwent treatment.

"He was texting me in the morning before I went into surgery, and we were FaceTiming the entire time I was in the hospital. He's seen me at my worst. He was there through all of that," she said. "I think that's why I feel the most beautiful in his eyes, because he still finds me beautiful after seeing all that."

And with the lengthy recovery, Hyland and Adams grew close before they could sleep together.

"It was a really intimate start to a relationship to have to go through those hurdles at the very, very, very beginning when you're just even getting to know a person," Hyland says. "Also, falling in love with someone before you can really be intimate. I did not believe that that was a thing, but it is."

This story was originally published on by Julie Mazziotta.