A fan of musical theater, Rian Johnson had long hoped to land the two stars. But he was already in the editing phase when they agreed to take part.When “Glass Onion: A Knives Out Mystery” isn’t setting up its actors to look like the possible perpetrators of a devious crime, the comic caper is reveling in its star-studded ensemble.There are of course the A-listers who populate the principal cast, including Daniel Craig, Janelle Monaé, Edward Norton and others. And there are the fleeting, unheralded appearances from famous faces like Ethan Hawke, Serena Williams and Yo-Yo Ma that function as rapid-fire visual gags.But a couple of these cameos now carry an unexpected poignancy. In the prologue of the film, which was released on Netflix on Friday, the sleuth Benoit Blanc (Craig) is in a melancholic funk, looking for ways to keep his brain engaged at the start of the coronavirus pandemic.We see Blanc relaxing in his bathtub, playing the multiplayer video game Among Us with a squad of online celebrities that includes Natasha Lyonne and Kareem Abdul-Jabbar.The other two members of Blanc’s eclectic gaming group are Stephen Sondheim, the renowned composer of musicals like “Company,” “Into the Woods” and “A Little Night Music,” and Angela Lansbury, the decorated stage and screen actor from “The Manchurian Candidate,” “Beauty and the Beast” and “Murder, She Wrote.”Both stars have died since work was completed on “Glass Onion” — Sondheim in November 2021 at age 91 and Lansbury this past October at age 96 — and the film may well be the final screen appearance for each of them.It’s a bittersweet occasion for their fans, a group that includes Rian Johnson, the writer and director of “Glass Onion” and creator of the “Knives Out” series. As Johnson explained in a recent video interview, he wanted the Sondheim and Lansbury cameos to stand as tributes to two of his favorite artists — and to give him an excuse to interact with these cultural greats whose paths he might not otherwise have crossed.Remembering Stephen SondheimThe revered and influential composer-lyricist died Nov. 26, 2021. He was 91.Obituary: A titan of the American musical, Sondheim was the driving force behind some of Broadway’s most beloved shows.Final Interview: Days before he died, he sat down with The Times for his final major interview.His Legacy: As a mentor, a letter writer and an audience regular, Sondheim nurtured generations of theater makers.New Books: The year since Sondheim’s death has seen an array of books offering further glimpses into his life. We look at some of them.Now, Johnson said, his experience in securing the involvement of his personal heroes has taught him never to take such opportunities for granted. “One thing I’ve learned is that every moment you get with somebody that you respect, savor that time,” he said, “and put yourself in that situation as often as possible.”While Johnson’s affection for Sondheim may not be immediately evident from his résumé — the filmmaker’s credits include “Star Wars: The Last Jedi” and the time-travel thriller “Looper” — Johnson grew up a fan of musical theater, and included a shout-out to Sondheim in the original “Knives Out”: a scene of Craig lost in thought as he sings along with “Losing My Mind,” from the Sondheim musical “Follies.”Sondheim was also a lover of wordplay, games and crossword puzzles, and he enjoyed orchestrating murder-mystery parties with his friend Anthony Perkins. He and Perkins wrote the screenplay for the 1973 whodunit “The Last of Sheila,” which starred James Coburn, Dyan Cannon, Raquel Welch and Ian McShane, and which Johnson proudly cited as a source of inspiration for his “Knives Out” films.Sondheim’s ties to the mystery genre go deeper still: his only nonmusical Broadway production was the play “Getting Away With Murder,” which he wrote with George Furth and which ran for just over a month in 1996. In an interview with The New York Times that year, he recounted how Laurence Olivier had told him he’d used Sondheim as his model for the game-loving mystery author he played in the 1972 movie “Sleuth.” (In the same interview, Anthony Shaffer, the author of “Sleuth,” denied a longstanding rumor that he had originally titled it “Who’s Afraid of Stephen Sondheim?”)Through his love of Sondheim’s musicals, Johnson was introduced to Angela Lansbury, who played Mrs. Lovett in the original Broadway production of “Sweeney Todd,” as well as a filmed version that played frequently on Johnson’s television. That is, when Johnson wasn’t glued to “Murder, She Wrote,” the cozy CBS series that cast Lansbury as the crime-solving author Jessica Fletcher. For children of the 1980s, that show “was actually pretty pivotal in installing a love of whodunits and murder mysteries into all of our brains,” said Johnson, who also slipped a few seconds of a Spanish-dubbed “Murder, She Wrote” episode into the original “Knives Out.”Ram Bergman, Johnson’s producing partner, said that Sondheim’s and Lansbury’s cameos were recorded during the editing of “Glass Onion,” as he and Johnson tried to reach them, working every connection they had.In Sondheim’s case, Bergman said, “I wasn’t really sure how to get to him. But then I was on a call with Bryan Lourd, our agent, and it somehow came up. I said, we really would love Stephen to do this. And I swear, five minutes later, he emailed me: he’s going to do it.”Bergman added, “Rian was in heaven, and I was in heaven because I knew how much he meant for Rian.”Sondheim performed his contribution on a recorded Zoom call. In that conversation, Johnson said, “I mentioned to him that we were trying to get Angela Lansbury. And he said, ‘Oh, Angie — I’m friends with her. Tell her I’m doing it. She’ll do it.’”Later on, Johnson went to Lansbury’s home in Los Angeles and recorded her portion on his laptop computer.“She couldn’t have been lovelier and more generous,” Johnson said, adding that Lansbury was perfect for the scene in every way except one: “Not a gamer,” he explained. “And so she was very patient in letting me describe the rules of Among Us, up to a point. At which point she just said, ‘You know what? Just tell me what the lines are. I’ll trust you.’”Those were Johnson’s only interactions with Sondheim and Lansbury before they died. In each of his conversations, Johnson said, he wasn’t ashamed of sharing his admiration for them.“I allowed myself to have that little awkward moment of saying to them what I’m sure every person who meets them says,” he said. “But still, it felt really nice to tell them that I wouldn’t be here doing this if it weren’t for them.”Getting to pay this kind of posthumous homage to his idols is a bittersweet distinction, Johnson said: “It’s sad, because as a fan, I wish they were still around and making stuff,” he said. “I hope they would have enjoyed the little scene and gotten a laugh out of it.”Natasha Lyonne did not get to interact directly with Lansbury or Sondheim but is no less proud to be part of it.Asked what it was like to have played even a minor role in their curtain calls, Lyonne replied in the arch spirit of a “Knives Out” movie: “Honey, I know what you’re getting at and it wasn’t me,” she said. “I have alibis for both.”Then, with more sincerity, she continued, “It goes without saying that they were giant losses of two incredible lives well lived. I guess we’ll only know if I make it to 90, if I was actually worthy of being up there with them.” More