For five seasons, fans of “Jane the Virgin” have swooned over the transformation of Rafael Solano from playboy hotelier to doting baby daddy and the wokest bae in Miami.

But for Justin Baldoni, who plays him, that evolution wasn’t just an act.

“What’s interesting about the journey of Rafael as a character is it in some strange way resembles and intersects with my journey as a man,” he said. “I explored masculinity, digging into the parts of myself that are uncomfortable, and learning about equality and privilege. And it really cracked me open.”

It’s still anyone’s guess whether Jane (Gina Rodriguez) and Rafael will get their happily-ever-after in the CW telenovela’s finale on July 31 — the “after” including the return from the dead of Michael (Brett Dier), Jane’s first husband, and a series of unfortunate events that keep derailing her wedding to Rafael .

Wherever the soundstage sun sets, Baldoni’s offscreen metamorphosis is ongoing.

Baldoni, now 35, began directing music videos and commercials when he was about 21, even giving up acting at one point — his résumé includes soapy stints on “The Young and the Restless” and “The Bold and the Beautiful” — to make documentaries. Following his feature debut, “Five Feet Apart,” in March — starring Haley Lu Richardson and Cole Sprouse as cystic fibrosis patients who are in love but who dare not touch — Baldoni will soon begin preproduction on “Clouds,” about a teenage cancer victim. Both connect back to stories in his digital docuseries, “My Last Days,” now shown on CW and SoulPancake, that follows terminally ill people as they come to the end of their lives.