Hey guys. I want to know if my classes inheriting from MonoBehaviour affect performance or not.
Thanks.
If you don’t need MonoBehaviour’s features for certain classes, don’t inherit from it. Of course anything you want to attach as a component to GameObjects need that.
Monobehaviours might have calls to Update and others and more you have that stuff there, it will cause more work for the CPU for sure.
Inheriting from Monobehaviour does not affect performance at all, unless you implement some of the ‘magic’ methods like Update(), Start() etc and leave them empty. In that case, those Methods will be invoked wasting some cycles. But if you don’t implement them, there is no overhead. This is because in the background Unity keeps a list of all Monobehaviour classes that have methods with magic names, and this list is compiled before the app starts. So it will not waste time on examining a MB-derived class to determine if it implements Update(). That is also the reason why you don’t have to declare Update() etc to be ‘public’ - Unity will find and execute them anyway. The flip side of this (and this was the design goal) is that MB classes do not waste time during execution to determine if a Magic method exists. So if you don’t Update, simply don’t implement it and you will not lose performance.