“Avengers: Endgame” actress Karen Gillan was in her trailer on the set of 2014’s “Guardians of the Galaxy” when she heard a knock. Someone was eager to see her intricate makeup as Nebula, an adopted daughter of the intergalactic warlord Thanos.

A mustached smile greeted her. It was Stan Lee.

The legendary writer, who became the guiding force behind the rise of Marvel Comics, gasped at her hourslong cosmetic transformation into a purple and blue space pirate. Gillan was about to film a major fight sequence, she told him as they parted ways. Lee turned around, clenched his fist close to his face and uttered, “Knock ‘em dead.”

“That’s the coolest thing that’s ever happened to me,” she said at Monday’s “Avengers: Endgame” world premiere in Los Angeles. The movie opens Thursday.

Lee, who died in November at age 95, was on the minds of several stars and filmmakers.

Anthony and Joe Russo’s movie features Lee’s final film cameo, marking the end of an era after 11 years of surprise appearances throughout the Marvel Cinematic Universe. The studio will release a behind-the-scenes video of the iconic cameos.

Benedict Wong, who plays Doctor Strange’s sidekick Wong, described the event as bittersweet. “As much as it’s a real joyous moment, it’s obviously tinged with sadness,” said the actor, who saw Lee a few times. His favorite was the first time they met, at 2016’s “Doctor Strange” premiere.

“I just made a beeline over to him and sort of fanboyed him,” Wong recalled. “I just said, ‘Stan, you don’t know me’ and he immediately interrupted and said, ‘You’re Wong. You’re great!’ And it was a big welling-up moment.”

Executive producer Trinh Tran laughed as she remembered Lee’s “Endgame” scene. “People you normally wouldn’t even see on the set showed up, and you’re like, ‘Where did all these hundreds of people come from?’ He has that impact on all of us. Not just the fans, like the crew are his fans. We love him. We wouldn’t be here without him.”

Co-writer Christopher Markus put it this way: “It was like Santa came to set.” He said the cameo was developed before Lee’s appearance in the March release of “Captain Marvel.”

“You know, you don’t give Stan Lee a page of dialogue,” writer Stephen McFeely said. “You give him one full thing where he can shine.”

Look out for Lee in a driving scene, said second unit director Sam Hargrave, who shot the sequence with Lee and a stunt double.

Actors Chris Hemsworth (Thor) and Paul Rudd (Ant-Man) joined in on the collective nostalgia Monday.

“I just remember the sort of childlike wonder of that guy and the love for these stories,” Hemsworth said of Lee.

Rudd recalled hanging out with him on the set of 2015’s “Ant-Man,” when Lee expressed his excitement to see Scott Lang on the big screen. “He was going to finally see the scale of it as he always imagined,” Rudd said. “That was really thrilling.”