An endless horde overwhelms our heroes. Defeat looks inevitable. But wait! There’s a central “hive queen” pulling the puppet strings, and if the good guys can just disable that boss, the evil army will collapse.

For up-to-date “Game of Thrones” viewers, this might sound familiar. Similar storylines play out with the “brain bugs” in “Starship Troopers” or the “Mind Flayer” in “Stranger Things.” For writers, it’s an easy way to flip the bleakest moment of a story into a happy one.

“My guess is they do this because they need to figure out a way for the heroes to save the day,” said Simon Garnier, the head of the Swarm Lab at the New Jersey Institute of Technology.

But this trope is based on a long-debunked idea that undersells how unusual and interesting real swarms are. Let’s say you come at the king and don’t miss. Even so, the swarm should still keep coming.

This “hive mind” concept has floated around in science fiction since the 1930s. But it has clear roots in biology. Entomologists have long grappled with how insects like bees, ants, termites and wasps achieve eerie feats of coordination. Until just recently, some experts believed these societies were strict hierarchies.

“In most of the work on bees and termites until the beginning of the ’90s, you find this kind of idea that the queen is a central organizer,” says Guy Theraulaz, an expert in swarm intelligence at Paul Sabatier University in France.

But today, researchers believe the truth is even stranger than science fiction. No individual ant or bee has the neural power to process a whole colony’s information and issue marching orders. Instead, individuals follow basic rules for how they interact with other swarm members. Coordinated problem-solving emerges from those rules, even with nobody at the helm. That same decentralization makes swarms durable because they have no single point of failure.

Insect queens are more like reproductive organs for their colonies.

“The colony is not just dropping dead just because you remove the queen,” Garnier said. Some colonies might slowly peter out after losing one, he said, but many species will simply promote a new queen.

To be fair, not every dramatization of swarms features a central brain. Theralauz praises the machine swarms in science fiction novels like Stanislaw Lem’s “The Invincible,” and Michael Crichton’s “Prey.”

Other examples try to have it both ways. Consider “Star Trek”’s Borg, a catchphrase-happy collective consciousness made up of humanoids with high-tech implants that wants to assimilate other species. In their first appearances in “The Next Generation” TV series, they have no central leader. But the 1996 film “Star Trek: First Contact” gave them a queen. She says she doesn’t command the rest, but when she dies, the surrounding drones shoot off sparks and collapse.

A more realistic depiction of swarms would take away their Achilles heel, requiring screenwriters to figure out new tricks. “It would be cool to see a movie with an actual decentralized swarm,” said Ariana Strandburg-Peshkin, a collective behavior researcher at the University of Konstanz in Germany.

To beat a foe like that, she said, you could still try to remove individuals who have a greater-than-average sway over the whole network. You could introduce a few nudges of misinformation that would redirect the flock. Or you could warp the very foundation of the swarm’s intelligence, the rules that govern how individuals interact, by adjusting something small in their environment like the temperature.

“I’m not sure why the swarm is always evil, though,” Strandburg-Peshkin said. “I would also like to see a movie where the swarm is actually good.”

This article originally appeared in The New York Times.