From left: Janelle Monae, Taraji P. Henson and Octavia Spencer in “Hidden Figures.” (Hopper Stone/SMPSP/20th Century Fox)

There are no guarantees in life, least of all in the movie business.

Megastars Ben Affleck and Martin Scorsese have reliably provided hits before. But both men’s films bombed at the box office during their wide releases. Over the holiday weekend, Affleck’s “Live by Night” brought in an estimated $5.4 million and Scorsese’s “Silence” earned a projected $1.9 million.

Instead, audiences are flocking to watch an inspired-by-a-true story picture about three black female mathematicians working at NASA during the height of the space race.

Hidden Figures” topped the box office for the second weekend in a row. The movie is on track to earn more than $25 million at the box office from just the holiday weekend, after garnering nearly $23 million the weekend before.

The success of “Hidden Figures” comes as debates over racial diversity and gender pay equity dominate Hollywood. And its stars have pointed to the film as proof that movies helmed by black women are not inherent commercial risks.

“I have been told my entire career ‘Black women can’t open films domestically or internationally.’ Well anything is possible,” star Taraji P. Henson wrote on Instagram after the movie’s opening weekend, when it took the No. 1 spot at the box office. “Most importantly this proves that PEOPLE LIKE GOOD MATERIAL. HAS NOTHING TO DO WITH GENDER OR RACE. Agreed?!”

“Hidden Figures” stands out in a landscape where few top-grossing films have female leads. In 2015, just 22 of the top 100 domestic-grossing films had female protagonists, according to a San Diego State University study, while 13 percent of all female characters in the top 2015 films were black.

In addition to having fewer films with female protagonists, when such movies do get made, they tend to have smaller budgets (as they’re usually not huge action flicks with major special effects) and smaller distribution, said Melissa Silverstein, founder and publisher of Women and Hollywood, a site specializing in women in movies.

“Hidden Figures” cost about $25 million to make — a fraction of the roughly $40 million budget of Scorsese’s “Silence,” and the $65 million that Affleck’s “Live by Night” cost.

With “Hidden Figures,” what audiences are saying is “give us more, we will go,” Silverstein said.

“It’s a feel-good movie, an upbeat movie, a movie about STEM that stars three black women: This is like the anathema to what we think most Hollywood is, which is these big tent-pole movies,” Silverstein said.

When such movies do well, it may cause decision-makers to rethink what it takes to appeal to a broad audience.

“This illuminates the need for diversity and inclusive storytelling all year long,” Silverstein said. “There is a market for these [films], and if the movie’s good, it will sell.”

“Hidden Figures” benefited from rave reviews and an awards season boost; Pharrell Williams (responsible for the movie’s score) and actress Octavia Spencer were both nominated for Golden Globes.

A number of factors could have contributed to the poor performance of the Affleck and Scorsese projects. “Silence” clocks in around 2 hours and 39 minutes and was completely shut out by the Golden Globes. Affleck’s “Live by Night” earned tepid reviews and, as a gangster movie, struggled to get noticed amid a movie season cluttered with fresher subject matter.

“The difference with ‘Hidden Figures’ is it’s a movie we had not seen before,” Silverstein said. “We didn’t even know these women existed, so what ‘Hidden Figures’ has done is unleashed stories of people whose achievements have gone unnoticed in our culture.”

Despite the lackluster performance for Affleck and Scorsese (whose “Silence” was at first independently financed), they will likely continue to head up big-budget projects. Affleck, for instance, will direct and star in a “Batman” movie for Warner Bros.

“We’re in the Ben Affleck business and we look forward to future projects,” Warner Bros. domestic distribution president Jeff Goldstein told the Hollywood Reporter. “Unfortunately, ‘Live by Night’ didn’t connect with audiences.”

Of “Silence,” Paramount’s president of marketing and distribution, Megan Colligan, told the outlet that “this is a movie we will continue to support and expand.” She added: “Marty truly is one of the greatest living filmmakers, and this is a movie he desperately wanted to make.”

Correction: This story has been updated to say that Melissa Silverstein’s site is called Women and Hollywood, not Women in Hollywood.