Multiplayer RTS Unit Selection

Godot Version

4.6+

Question

I’m making a multiplayer Real Time Strategy game, and I want to be able to select 0 or more units at a time. I am working on creating units right now; they’ll all extend BaseUnit. I have player controllers, which are just cameras with a script attached, and a Global script. Should I store who’s selecting a unit inside the unit’s script, what units are selected inside the player script, or what units each player has selected in the Global (synced to all peers) script? I think the last option is the one I want, as I also want to display to players what units other players have selected.

A second opinion would be great! Thank you!

I think having a global UnitManager script would be a good way to do this! that way it can have arrays of your units that are easily referenced everywhere.

I prefer to create a manager that controls entire game, e.g unit manager for your RTS, it registers inputs (as they’re global) and assigns functions to them

if i were you - i’d listen for inputs, for instance clicking, and then check if there was any unit where i clicked (areas 2D are simpliest way to do this) and then i have a list of selected units where i add or remove unit from like:

var units: Dictionary[Player, UnitsList]

and when i add / remove unit i also set / reset it from the list, it also stores player reference so you can check units of each player

Wouldn’t it be simpler to add a “selected_units” property to each player? e.g.:

@export var example_player: Dictionary = {
	"id": 1,
	"custom_name": "Jerry",
	"selected_units": {
		$"/root/[...]",
	},
	"color": Color(1, 0, 0),
}

It would. Stay away from “managers”.