The post-credits scene of Avengers: Infinity War hinted that the key to defeating Thanos and undoing the destruction he wrought might be Captain Marvel. The powerful hero will make her debut in 2019’s Captain Marvel starring Oscar-winner Brie Larson, but she’ll also feature in Avengers 4. In fact, due to the way Infinity War and the next Avengers flick were shot back-to-back, Larson actually filmed her Avengers 4 scenes first.

The events of Avengers 4, the currently untitled sequel that will once again be directed by the Russo Brothers, won’t be in a position to spoil the events of Captain Marvel. The hero’s origin story, which is being directed by Anna Boden Ryan Fleck, comes out before Avengers 4 does and it’s set in the ‘90s, well before the events of Infinity War. Still, filming scenes with Captain Marvel before she’d had a movie — and origin story — of her own, was tricky. Stephen McFeely, one of the screenwriters behind Avengers 4, said as much in a conversation with Collider.

We were in the position we were in with Spider-Man and Panther where Brie was going to have to shoot her scenes, I think its okay to say, before she shot Captain Marvel. So, we can’t really talk about what we decided, but it was clearly a conversation we had to have with Ryan and Anna who didn’t exist yet before when we started that process. So, you are bringing directors on and were trying to set up something that will work for our movie and not screw up their movie

As McFeely said, the MCU has done this before. Spidey and Black Panther both made their debut in Captain America: Civil War before headlining their own movies. Still, with Captain Marvel the complications seem a little bit more intense given the secrecy around the Avengers 4 plot and Captain Marvel’s ‘90s origin story.

Captain Marvel opens on March 6, 2019, while Avengers 4 opens on May 3, 2019.

Photos via Marvel