Yeah, Star Wars isn’t actually a good counter example there. Even just looking at the Tales of the Jedi era stuff. There’s a lot of primitive worlds where you don’t have advanced ranged weapons, and when you’re dealing with them, plasteel armor and a blaster will still offer an insurmountable advantage. The only reason the Jedi can get away with using a lightsaber is because of their superpowers.
I mean, this is worth talking about, because you can legitimately have characters who approach combat from a melee perspective in a setting with advanced ranged weapons. And Star Wars is one of those settings, but you really need to evaluate who can and can’t get away with using melee weapons.
You don’t want to arm Rebellion Era Stormtroopers with vibroswords because their armor won’t fully protect against blasters. We see enough getting gunned down in the original trilogy to make that point. Now, their armor does (apparently) save their lives sometimes. There’s a scene at the beginning of A New Hope, where the Stormtroopers are checking their fallen buddies, poking them. The assumption is to see if they’re actually wounded, but still alive.
If I’m remembering correctly, The Empire still issued vibroblades to some specialized Stormtroopers as a backup. Because, if your primary weapon fails, and you really need to kill someone, it’s a good idea to have a contingency.
It’s the same reason modern militaries still issue combat knives. It’s not that you’re expected to kill people with them, but if you’ve got nothing else, it’ll still do the job.
Star Wars does occasionally throw in energy shields to protect against blasters. It also occasionally says these are far too heavy to be man-portable, and so you can use them to protect capital ships, facilities, and (sometimes) very heavy vehicles, but the setting is infinitely creative in finding ways to negate that. Energy shields don’t protect against guided projectiles. I can’t remember how widespread the PLEX troopers are in the legacy EU, but there are plenty of counters to energy shields, including concussion rifles, sonic weapons, disruptors, and classic slugthrowers. You can probably engineer armor to deal with some of these, but not all of them (and as far as I know, Star Wars’ disruptors are a kind of “screw you and the rules you rode in on, bzzzap” option that really doesn’t have an effective counter.)
In the middle of this, you do have characters who are superhumanly agile, prescient, and can negate most incoming projectiles. Saying they carry melee weapons, because it’s a badge of office isn’t really that strange. Especially when you consider their full power set.
The idea that you’d intentionally give front line combatants melee weapons in Star Wars, without also gearing them up in ways the setting doesn’t normally support, and doing it for non-cultural reasons, is a lot less plausible.
Also, Knights of the Old Republic’s “cortosis weave is everywhere” argument has always struck me as really stupid. Cortosis is this rare, brittle, ore that shorts out lightsabers on contact. You see it in the Tales of the Jedi comics, which is what Bioware was specifically adapting from… or was supposed to be adapting from when they made KOTOR.
Thing is, even in that timeframe, Jedi are vanishingly rare. So, even if the Star Forge can produce the stuff en mass, for the Sith (before it’s destroyed), it doesn’t explain why every biker gang and Tusken Raider you encounter is using this rare and expensive anti-lightsaber material in their weapons and armor. Which is even weirder when you consider you could just take that money and get a disruptor for less. “Jedi problem? Just blast through them, same as everything else from pesky Jawas up through Krayt Dragons.”
The reason you don’t see more disruptors is because they’re not cost effective. The things they counter are rare enough that it’s not worth the expense, which applies even more strongly when looking at Cortosis. Because you’re far more likely to run into someone with an energy shield or heavy armor than one of the handful of lightsaber users in the galaxy.
The focus on melee is a gameplay consideration. KOTOR (the original game) pushes the player towards a melee build because they’re going to be giving you a lightsaber. That’s supposed to be a surprise, even though it’s also, literally, a bullet point on the back of the box, so you’re quietly encouraged to go that route, even though it would normally be a very bad idea.
There are sci-fi settings that use front line melee combat, with specific considerations to make it plausible.
Dune brings out the melee weapons on Arakis because (if I’m remembering correctly) the atmosphere does horrific things to Las weapons. The books still use ranged weapons, though. It also brings out melee weapons, for ceremonial reasons, in formal duels. Star Wars’ lightsaber duels are a kind of similar reason, and it’s also part of the justification for Star Trek’s Klingons keeping their ridiculous bat’leths around. That Klingons are also exactly the kind of dudebro idiots who would run into gunfire waving a sword is also probably a factor.
The hunters from the Predator films are an in between. Their melee weapons are, mostly ceremonial. So they’re using them in combat as a kind of macho affirmation. It’d be a lot less forgivable if their entire civilization wasn’t built around trying to hunt sentient creatures through stealth and guile. Also, given they tend to start their hunts with plasma casters, and then switch down to melee weapons when the odds are less unfavorable, or the caster brakes, it’s fairly clear they don’t think they could just wade in and use those exclusively.
Star Trek also has the Hirogen, and Jem’Hadar. The Hirogen are basically knock-off Predators. Again, they’re using stealth to get in close to use melee weapons. But, they’re also happy to stay at range, and obsessed with mounting improbably large skulls on their walls. The Jem’Hadar use personal invisibility to outmaneuver foes. As with the Klingons they do use melee weapons in combat, but they’re a lot more selective about that. Switching over when they’re either low on ammunition or in very tight quarters, like boarding enemy ships and stations.
Warhammer 40k includes a lot of units that can take absurd amounts of punishment, so they can actually close to into melee while getting shot. Or, with Tyranids, where it doesn’t really matter if you kill them, because two hundred million of their buddies will be dropping by while you’re reloading.
40k’s melee units also tend to be highly mobile. There are exceptions, but from Assault Marines to Warp Spiders, if they can’t kill you at range, they probably have a nasty way to get in touch.
The xenomorphs from Aliens are another legitimate melee user. In the films that skew towards individual aliens, they hunt through stealth, picking off lone characters. It is a horror movie monster after all. But, especially for something that can go up any surface, in a dense industrial environment, that is a real option.
In the films that focus on hives, it varies, but we’re back to the Tyranids’ solution to the problem, more bodies. There are more of them than you can kill before your Pulse Rifle runs dry. It also helps that the second film is an allegory for the Vietnam War. So, the tactics the aliens are engaging in, and the technological disparity between the marines and xenomorphs serves a thematic purpose as well.
I’ll blame Jim Sterling for reminding me of this, but another example is Dead Space. The Necromorphs are sculpted from dead tissue. So, there isn’t really a way to kill them. All you can do is carve them apart. Which only stops that necromorph temporarily. There’s no permanent way to get rid of them, and because they’re already dead, conventional firearms won’t do much. The games solve this through horrific application of power tools. But, again, that’s a temporary solution.
Come through a deck in the first game once, and you’ll see the dead and dying everywhere, and leave some more necromorph corpses on the way through. Come through again later, and all the corpses will be gone, because they’ve been retrieved and recycled by the infestation.
Of course some Necromorphs do have ranged attacks, including bone spikes and acid spit, but the melee enemies that use reshaped bone blades make sense once you realize they’re (basically) a renewable resource, and that the infestation can change up the creatures it’s producing to deal with the situation at hand.
There are legitimate reasons to have melee weapons in a setting. The problem is, you can’t forget about ranged options. And, as a general rule, if someone does find a way to counter your ranged weapon, you’ll have a significant advantage if you can figure out away around that counter before they can. This is the exact same technological evolution that took us from the Tu Huo Qiang to the AK74, and M16a1. If you build better armor, and someone else is going to build a better gun.