Ludwig Göransson, the Oscar- and Grammy-winning composer of “Black Panther,” faced a tricky assignment when he took on “The Mandalorian,” the new “Star Wars” series launching this week on the Disney Plus streaming service.

“It’s a new medium, a new set of characters — and it has a certain tech-y grittiness, because you’re dealing with a very dystopic setting,” says executive producer Jon Favreau. “The Empire has fallen and chaos is beginning to reign in the galaxy, so the romantic strains of John Williams’ score would not sit well against the imagery that we have.”

Yet this is still “Star Wars” (even if it’s about an interstellar bounty hunter who rarely speaks and whose face we never see) so the creative team didn’t want to dispense with the traditional orchestra entirely. “It still has the soul of ‘Star Wars,’” says Göransson.

The Swedish-born, L.A.-based composer came up with a novel solution: He would play many of the key instruments himself — unusual woodwinds, drums, guitars, piano, percussion — add a 70-piece orchestra for that “Star Wars” touch, then apply modern production techniques for an even more alien soundscape.

He began work before shooting started last fall, reading scripts and coming up with musical ideas — particularly the sound of a bass recorder for the mysterious, unnamed title character. He spent a month in his studio inventing the themes and musical colors for the rogues and renegades who live at the edge of the galaxy.

“I was closed off for 10 hours a day, just coming up with music and sounds, going from instrument to instrument,” he says. “There weren’t a lot of computers involved. It was just me playing, so it felt timeless.”

Favreau and his producing partner Dave Filoni (“Star Wars: The Clone Wars”) immediately approved the echoing notes of the bass recorder for the lead character. Notes Göransson: “It’s a very original, distinct, lonely sound that follows this gunslinger on his journey.” The music provides “the facial expressions” that we never see, as the Mandalorian never removes his helmet — which, along with his armor, further inspired the composer to add “metal sounds” throughout the score.

As he began to see footage and compose to specific scenes, he combined his recordings of individual acoustic instruments with more modern sounds, including synthesizers and cutting-edge processing. “You take these organic drum sounds or percussion sounds or flute sounds and then make them sound different or modern using the tech,” Göransson adds.

He then recorded an L.A. studio orchestra, many of whose members were playing John Williams’ score for the upcoming “Star Wars: The Rise of Skywalker” on different days of the same weeks during the summer months.

Favreau knew Göransson’s work not only from “Black Panther” but also because both he and Göransson have collaborated with Donald Glover: Favreau on “The Lion King” and “Spider-Man: Homecoming,” Göransson sharing song of the year and record of the year honors with Glover’s alter ego Childish Gambino at this year’s Grammys.

“Ludwig has one foot in traditional score and another foot in technology, creating sounds that feel very musical even though he’s using nontraditional methods and instruments to achieve that,” Favreau says. He and Göransson talked about the Western and samurai influences that Favreau saw in the series, particularly the films of Sergio Leone and Akira Kurosawa featuring mysterious, well-armed loners in strange places and offbeat musical scores.

The primitive-sounding flutes, massive tribal drums, exotic plucked-string instruments and ugly metallic scrapings combine with airy synths and traditional strings and brass for a unique yet still unmistakably “Star Wars” ambience.

In addition to the Mandalorian (played by Pedro Pascal), the subsidiary characters, including Greef Carga (Carl Weathers) and Cara Dune (Gina Carano), sport their own musical themes. “Stylistically, I’m all over the place,” Göransson says, laughing, “but it’s all connected.”

The four hours of music he penned for the eight episodes constitute the longest score he has written to date, and the longest time he’s ever spent on a single project, having begun last November with those initial ideas, then composed and recorded from April to September. Disney Music Group will release a mini-album of Göransson’s work after each episode.

“Ludwig’s music has given ‘The Mandalorian’ its own identity, apart from, yet related to, ‘Star Wars,’” says Favreau. “We were departing definitively from what has come before, yet we wanted to feel like it was a continuation — a dichotomy of goals. It took somebody with a strong musical vision like Ludwig to do it.”