Zachary Levi may be lighting up movie screens as the delightfully childish superhero Shazam today, but just a few years ago, a divorce, the loss of his mother, and a missed Marvel role had driven him into darkness.

His journey back from that dark place became a vital part of how he earned the starring role in Shazam!

DC’s latest release, Shazam! tells the story of a 14-year-old boy named Billy Batson, who gains the ability to transform into an adult superhero whenever he says the word “Shazam!” The twist is that he retains his teenage mind while in an adult body. Zachary Levi, who was best known for his role as the titular character in NBC’s spy dramedy Chuck, plays the transformed, superheroic Billy, while Asher Angel portrays his teenage incarnation.

Levi told Men’s Journal about his struggles back in 2016, when he was one of two finalists for the role of Star-Lord in Guardians of the Galaxy — the other, of course, was Chris Pratt, who shot to superstardom after receiving the part. The disappointment of this missed opportunity combined with the pain in his personal life brought Levi to a place where he “didn’t understand why [he] wanted to live anymore.”

But Levi has always been a fighter, and he knew he had to treat his mind as carefully as he treats his body: “If we have a cavity, we go to the dentist. If our body hurts, we go to the doctor.” Levi went on a three-week intensive therapeutic retreat, where he was treated by mental health professionals, and did art therapy, yoga, and meditation. He also began working out regularly and consulted a nutritionist.

“It was an incredible one-on-one therapeutic, healing, spiritual deep dive into figuring out the pain and sadness,” which stemmed from his difficult upbringing by an alcoholic mother and an absent father, Levi recalled. He learned that “it’s OK to seek help. That’s… courageous—that’s brave.”

Taking the time to heal his mind brought Levi back to a brighter place, just in time for his video audition for Shazam! 

Watching Levi as Shazam for the first time, director David F. Sandberg knew immediately that he was perfect for the role. Levi, who was still at the intensive retreat when he filmed his audition, heard back from his agent within a day and was officially cast within a week. 

“He has this enthusiasm and excitement about things that feels very much like a kid,” Sandberg explained. Levi’s role as Shazam is a tricky one, as the hero is a 14-year-old boy in the body of a classic superhero.

With Levi’s renewed outlook on life, he perfectly embodied the duality of the character: the excitement and youthful optimism of a teenage boy who discovers he has superpowers and the maturity and bravery of a man who knows to ask for help when he needs it.