I’ve been tinkering around with RTS style gameplay, coming up with various ways of handling unit selection. The maximum amount of units I want able to be selected at once is 24, so there’s not going to be a LOT of data being passed around.
The first solution I came up with was an empty gameobject with a script attached handling selection methods. This object has two empty children, Active & Inactive. When a unit is tagged for selection its parent is transferred to the Active object, when a unit is no longer selected its transferred to the Inactive object.
If it’s set up this way I can quickly and easily iterate through Active’s children when I need to move around my selected units, or handle the Inactive units through a quick iteration as well.
The other solution I tried was adding units to a list when they’re selected, then removing them from the list when they are unselected. This was more of a pain in the ass getting things to communicate properly between the units and selection handling, as well as converting my list to an array in order to iterate through it. I also found myself using Transform.GetComponent quite often.
My question is, is one method slower/faster? Should I avoid parenting or lists for a task like this? Anybody know of any other solutions that might be better?
If anybody has some object oriented solutions for this using inheritance, interfaces, or whatever else there may be, I’d like to see.
Thanks for reading