Storing Unit Stats - Best Practices?

Hi guys, I have a quick question for you :slight_smile:
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! :slight_smile:

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.

Performance wise, don’t worry about it.
There sure are many other factors, such as cpu cache, but seriously, don’t worry about it. It won’t ever be enough to make a measurable diffence in a game (you might consider micro-optimizing like this when you are writing a high-performance engine part, or something). Especially when you are PROTOTYPING.

Think about what is easier for you, in the terms of balancing or other future features.
I prefer to create a UnitType object somewhere in the asset database and just assign that - just so I can tweak units globally and don’t have to worry about level designers overriding prefab values - but that exactly same reason can also be a drawback (you might want the level designer to instantiate a slightly modified unit).

In conclusion, don’t worry about performace and do what’s more practical, and in a prototype, what’s faster to do