Cole Sprouse went to great depths to get into the mindset — and body — of his latest lead character: a young man with cystic fibrosis (CF) who falls for a woman suffering from the same illness.

The 26-year-old “Riverdale” star said he did thorough research as he joined the cast of the romance film “Five Feet Apart,” which hit theaters this week. Sprouse said portraying a CF patient really opened his eyes and helped him better understand those with the genetic condition.

“It’s one of those illnesses that everyone sort of knows the name of but doesn’t really know the gravity of,” Sprouse recently told People.

Sprouse and Haley Lu Richardson, who plays his love interest 17-year-old Stella, both went on strict diets and studied CF before filming the movie directed by “Jane the Virgin” star Justin Baldoni.

“We built this whole nutritional regimen dedicated to embodying the physical limitations of cystic fibrosis. I lost 25 pounds for the role,” Sprouse told the publication, admitting it wasn’t an easy feat. “Everything we had to learn was covered in a mortality that was debilitating. But we were lucky enough to work with not only medical professionals who are extremely trained with cystic fibrosis, but also with patients themselves. I feel pretty well-versed about cystic fibrosis now.”

“In cystic fibrosis, a defect (mutation) in a gene changes a protein that regulates the movement of salt in and out of cells. The result is thick, sticky mucus in the respiratory, digestive and reproductive systems, as well as increased salt in sweat,” the Mayo Clinic explains on its website.

Sprouse has been working closely with the CF community to help educate the public about the condition.

“We made sure to be as accurate as possible,” Sprouse said. “And for us, the greatest feedback has been from the CF [cystic fibrosis] community going, ‘Yeah, we know that this is still a Hollywood production but it’s very clear that production has put a lot of attention to detail in how this thing really affects our lives.’ And that’s the badge of honor that we want.”

“We wanted this movie to feel sort of like a beacon of hope, and not feel debilitating. We’re certainly pulling on the heart strings, but we had curated the script and the performances in a way to make it feel hopeful, which we found quite important for the CF community and not just for the audience,” the star added.