Annette Bening brings some star power to "Captain Marvel," but it wasn't always going to be that way.

[Editors’ note: The following post contains spoilers for “Captain Marvel.”]

One of the more interesting twists in “Captain Marvel” is the true nature of Annette Bening’s character. While Bening had previously revealed she was playing the almighty Kree leader Supreme Intelligence, she did not disclose that she also appears as Mar-Vell. The character is the original Captain Marvel in the comic book created by Stan Lee. The key difference: Comic book Mar-Vell is a male while movie Mar-Vell is female. According to directors Anna Boden and Ryan Fleck, the gender swap happened “very late” into development.

“That was one of the epiphanies in the writing that came fairly late in the process,” Boden recently told Entertainment Weekly. “Too late in the process for comfort, to be perfectly honest!”

Just as in the comics, Mar-Vell was originally written as a man. Marvel Studios President Kevin Feige said the gender swap occurred so late that the film’s casting team had already begun looking at male actors for the role. “No one specific,” Feige said, “but we’d started looking at lists. And we were struggling with it, frankly.”

In the movie, Mar-Vell is a Kree who poses as a human research scientist named Dr. Wendy Lawson. The character ends up becoming a mentor to Brie Larson’s Carol Danvers and, just as the male Mar-Vell in the comics, becomes directly involved in the accident that leads Danvers to becoming her own version of Captain Marvel. Bening appears as Supreme Intelligence because the artificial entity takes the physical form of someone the person interacting with it most admires. For Carol, that’s Lawson.

“Pretty late in the process of writing it, I think I just woke up one morning and I had dreamt it or something,” Boden said of making Lawson/Mar-Vell and Supreme Intelligence the same. “I texted Ryan, and I was like, ‘Am I crazy that these could both be the same actor?’ And he was like, ‘Yes, you are crazy, and yes, you should talk to Marvel about it immediately.’ So it was a late-breaking idea, but something that I think helped pull those elements together in a way that it would’ve been hard to otherwise.”

Speaking to The Wrap, Feige said switching the gender of Mar-Vell was instrumental to the story at large. “It was really about the development of this story, and about how best to showcase Carol Danvers’ growth, and development as a hero, and the notion that she had a female best friend and a female mentor seemed important to us, and was something that was an idea that Anna had as the script is as she and Ryan were doing their pass at their script, and it all sort of fell together, particularly then with Annette Bening being able to play both of those spoilery parts.”

Boden and Fleck landed on Bening because “she’s got the great mentor quality, but she can also be really tough.” Those two attributes were essential for the one actor that could play both roles. “She can be regal, which was perfect for the Supreme Intelligence, and she can also just be casual and cool and laidback, which was necessary for Lawson,” Boden said.