- Home /
Is there such thing as a recommended Component cap?
This is more of a conscious check due to some performance issues my team has been encountering.
Is there by any chance a recommended cap for the number of Components/MonoBehaviours that can be created (through AddComponent()) and removed (through Destroy()) every FixedUpdate? Of course, I am not considering the obvious "the more objects created/destroyed, the less performance". I just wanna make sure I am not getting stuck in a pipeline that i am not aware of, or if there are any good Unity practices on such subject that I could learn (besides the also obvious "the less possible objects, the better").
Thanks in advance.
Well from my very short experience on mobile platforms, even with 15 fairly simple draw calls on the scene without optimization, destroy and instantiating prefabs has caused $$anonymous$$or hiccups in frame rate and slight pauses that definitely shouldn't be there.
I've added and removed primitive components without too many issues. When it comes to allocating memory with prefabs though, I definitely would recommend some form of object pool that is initialized and recycled ins$$anonymous$$d of using unity's instantiate and destroy.
dunno about rule-of-thumb limits on how often, but where possible, you might try disabling and enabling components rather than adding and destroying them; this would avoid any alloc/dealloc costs involved.
Your answer
Follow this Question
Related Questions
Clearing a LineRenderer Whiteboard, so that you can start drawing again 1 Answer
Difference between capitalized component in AddComponent and Destroy 2 Answers
Best approach for a distance based destroyer 1 Answer
Can't add component because class doesnt exist 1 Answer
Would abuse of inheriting from extended MonoBehaviour hurt the performance? 1 Answer