So I’ve been starting to think about performance a bit, since I’m working on a RTS-type game I would like to have 500-ish units at one time, so every piece of code I write has to be efficient since it will run on hundreds of objects.
At the moment my scripts dont rly use up much, like 5% in the profiler since I hardly use Update and focus on using Events for everything I can. At the moment I basically use MonoBehaviours for everything since its so convenient, but as you can see from my example below it can lead to a lot of Components on one GameObject. I am not running into issues yet but I read a lot about avoiding Mobobehaviours and using “classic” C# classes instead for performance, is this still something I need to worry about? The threads I can find are quite old and I cant manage to find a good reason as to why I should avoid MonoBehaviour, is it really worth the added complexity?
I don’t think that merely being Monobehaviours is going to cause you issues, at least not issues you would not have if you made them regular C# classes and called the same methods and did the same work yourself.
You do however win the award for the most heavily loaded GameObject I’ve ever seen, but looking at your scripts above, they certainly all seem at least somehwat reasonable things for some kind of entity to express. Nice compartmentalization!
For performance however, always test on target hardware. Performance in the editor is not relevant to how it will behave once built and running on your intended device range.
Thanks for the advice, I run a build every friday to test performance
Haha, yeah I think for this specific prefab I’ve gone a bit overboard but I am trying to stick to a 1-responsibility component system while avoiding inheritance if its not super clear case (i.e Animal → Dog, Cat). Its super easy to debug but comes with the downside of the extra MonoBehaviour overhead.