When the "Star Trek Beyond" cast and filmmakers gathered in Los Angeles last month for Anton Yelchin's funeral, they had a decision to make. Their film, the third in the rebooted series, was coming out in less than a month and a rigorous press tour was imminent. They could either put themselves out there to promote the film in the raw and devastating weeks following the death of their beloved co-star, or they could withdraw.

"We came to the conclusion in the end (that) if we withdraw, we're going to risk not helping a film that should be seen, not least because it stars Anton Yelchin," said Simon Pegg. "That's how we found the strength to be here ... It's hard to talk about, but we don't want to not talk about it. If we don't talk about it it's like we're ignoring it."

But persevering in the face of hardship and loss is in the fabric of "Star Trek," which is celebrating its 50th anniversary this year with this new tale of hope and unity in the federation.

"Star Trek Beyond" was supposed to be business as usual, with a few tweaks behind the scenes. J.J. Abrams, who re-launched the series in 2009 with a new cast and directed the 2013 sequel had his hands full with "Star Wars: The Force Awakens," and would cede directing responsibilities to Justin Lin — the man who turned the lagging "Fast & Furious" series into an international phenomenon.

Gone, too, were screenwriters Roberto Orci and Alex Kurtzman. Instead, Pegg, who plays Scotty in the films, was tasked with taking on the additional responsibility of writing the screenplay with Doug Jung. It wasn't going to be easy. No blockbuster ever is. But the "Beyond" crew had an insanely short window to work with. By the time Pegg, Jung and Lin started on the story, it was the end of January 2015. They had to start filming in June.

"Justin was in a situation that no director should ever be in: Prepping a movie that wasn't written yet," Pegg said.

There was already a crew in Vancouver waiting for directions on what to build for the set.

"I equate it to us driving a car and building a road at the same time," Lin said.

In front of the camera things mostly looked the same. Chris Pine was back as Captain James Kirk, as was Karl Urban (Bones), Zoe Saldana (Uhura), Zachary Quinto (Spock), Yelchin (Chekov) and John Cho (Sulu), who is revealed to be gay in the latest film. There were a few additions, too, in Idris Elba as the terrifying villain Krall and Sofia Boutella as the scrappy loner Jaylah, who early on in the story process was referred to by the cast as "Hannah Solo."

And then, in late February 2015, Leonard Nimoy — the man who originated Mr. Spock — died of end-stage chronic obstructive pulmonary disease at age 83. While Quinto had taken over his character officially, Nimoy had appeared in both new films as Spock Prime and the door was left open for his return.

"We knew we were going to make a tribute to Leonard when it happened, but we thought let's make him part of the DNA of the story too," Pegg said.

So Pegg and Jung wrote Ambassador Spock's off-screen death into the film, using it to affect Quinto's arc, and also serve as an elegy to the actor.

Of course, no one could have foreseen that they would lose another before the film came out, and one of their youngest, in Yelchin who was only 27 when he died after being struck by his own car last month.

When the accident happened, Yelchin's work on the film was finished, but Lin was still a few weeks away from completion, and so part of his and his post-production crew's mourning involved revisiting all of Yelchin's takes — something Lin was all too familiar with. Paul Walker died while Lin's "Fast & Furious 6" was still in production.

The close-knit cast and crew of "Star Trek" were also able to say goodbye together at the funeral.

"It was this incredible bond from the very beginning with all of them. And the reality is that this experience, to be at the funeral with all of them, it was really the only kind of salvation for us," Abrams said. "We all had each other."

The series will live on, of course. On Monday Paramount Pictures announced that there will be a fourth film, which will see the return of Kirk's deceased father (Chris Hemsworth). As for Chekov, Abrams said they've started thinking about how to deal with his absence in the continuing story, but that it's also "too early to talk about."

"There is no recasting," Abrams said. "I know he literally was a re-cast of a prior thing, but ... we have some other thoughts."

Everyone is still processing the loss the best they can.

"It will never stop being terrible," Pegg said.

But he did find some grace and solace in seeing his friend up on the big screen again.

"I thought it was going to be really sad. At times it was. But for the most part, it was like 'there he is, he's right there,'" Pegg said. "He's alive and he's happy and he will be there forever."