- Home /
Does a script containing many variables affect performance?
Say I have a script which contains a bunch of large prefab objects (like enemies and map layouts), would it affect performance even though those objects aren't being instantiated?
Sorry if this is a dumb question.
Answer by LilGames · Jul 03, 2019 at 07:06 PM
Dozens, hundreds? or thousands and thousands of dynamically generated vars? I predict your answer is more like dozens or hundreds, in which case it's no issue.
As a little aside: What's gonna slow performance is Computation and Access. So, doing more things to your data will take time, and doing things with more data will take time. Particularly, how much data are you accessing at a time, and where in the computer itself is that data? Even if you have billions of variables, amounting to gigabytes of data, you're only slowing things down if you're actually accessing all of that data. If you only deal with a few megabytes at a time, and those megabytes are next to each other, then you can have a ton of data and not even notice. That's an oversimplified explanation of why ECS is such a great thing for performance, or how particle systems or voxel engines can run so fast. $$anonymous$$inecraft runs fast, but there's billions of blocks being loaded into memory, which is a fraction of the size of the world. It works because it only ever loads a few billion as opposed to a billion billion blocks, and it only ever does anything with a couple thousand blocks at a time, and does so infrequently.
Frankly, if you're having optimization issues, it's most likely a graphics issue, and if it's not, it's probably because a certain computation is inefficient. Use the profiler.
Your answer

Follow this Question
Related Questions
Animator.FireAnimationEvents giving 90ms spikes 1 Answer
I'm not seeing a performance increase with the Job System. Help 1 Answer
ParticleSystem performance optimization questions: Clear(), Stop(), SetActive(false) 0 Answers
Particle System 2D dont works in Game 0 Answers
Why Does it not Reset levels? 0 Answers