Hi guys, I have a quick question for you
I’m working on a little RTS prototype and was wondering if the following has any impact on performance (especially with higher unit counts):
Let’s take a simple stat like the “AttackDamage” that a unit deals. Units are built off the templates of unit classes (eg Swordsman, Spearman, Knight…).
Say, for example the AttackDamage of the Swordsman Class is 5.
So my question is: would it be better - at runtime - to copy the 5 into a script of each individual instance of the swordsman unit on the map when it is spawned. Then, whenever a specific unit attacks, it looks up the attack damage stored in its attached UnitStats script…
…OR is it better to have the unit remember ONLY which class it belongs to and then reference the UnitClassStats script of the parent class?
So the way I see it with my limited understanding of these things is: it’s a trade off between storing more data (a copy of the value in each individual unit) vs. a slightly more complex reference (to the unit class script) - is that correct? Does this even make any difference? Are there best practices?
Thanks in advance!
P.S. Of course there could be additional factors like upgrades or temporary buffs which probably would have to be sorted out on a per-unit basis.