- Home /
Unity Optimization Tips !
Hi Everyone, I am stuck on thinking which thing causes a lag in unity and how to optimize it.. i need help on the following topics !
Does The Length Of The Script Makes A Game Slower?
Which is better, a table made inside unity from 5 cubes or a table imported from a 3d modelling software carved out from a single cube?
Does the function Update reduces the optimization of the game? In other words does an empty function update in every script reduces the speed of game, even by 0.001%?
can co-routines be used as an alternative to Function Update?
Which is better Co-routine, update or fixed update?
I have a script in my game which generates about 100 low-poly trees, 100 low-ply rocks and 1000 traps(considering each trap having 4 blocks), and all these have a script attached to them, so in other words about 1200 scripts are working, is this ok?
Does making an object child reduces lag?
Which type of texture to use, low quality or high quality?
And finally, which sounds are to be compressed more, large sounds(like background musics, etc.) or short sounds(like spells, button click, etc,)?
How can i view the size occupied by each of the item in total? like texture occupies 100MB, sound occupies 80 mb, etc.
Thanks
EDIT : one maint thing i forgot to ask, which scripting language is optimizing wise best? Java, C++, or boo?
Answer by AlwaysSunny · Oct 25, 2014 at 06:40 AM
Script length doesn't matter. Maybe a teeny, tiny bit, but that's really splitting hairs. That said, script length does affect compile time. At runtime, it's all about what each line does.
Sounds like you're not yet familiar with draw calls, batching, and other optimization-specific aspects of the render pipeline. Bottom line, fewer objects is better, even if your group of objects has the same number of verts/tris as your single object. See the docs for more on this.
Having an empty Update(){} does affect performance. Probably by 0.001%, but yes. Empty functions are executed, which takes a measurable amount of time.
Co-Routines are a very powerful feature. A common usage for them is executing code every N seconds instead of every frame, which can offer huge optimizations depending on what's being done.
No such thing as "better" - Update is for things that must happen every frame. FixedUpdate is for things which interact with physics (it has other uses too). Co-Routines are not simply alternatives to Update/FixedUpdate/LateUpdate, but are tools you can use to build smarter, cleaner, and more efficient algorithms.
Having this many objects or scripts isn't "bad". It also doesn't sound super good. When working on projects with tons of objects and scripts, it's important to consider exactly how much work is being done, and whether you can reduce that workload. (Protip: The answer is almost always "yes" for a long, long time... Until it's not.)
Parent/Child relationships have almost no bearing on performance.
Import the highest quality textures you have. Their import settings and the project quality settings help determine whether high or low res versions are used.
All I really know about this is compression is good, until it's not. Meaning, compress as heavily as you choose while ensuring the sound quality is acceptable.
If you have Unity Pro, you have access to the Profiler, which gives detailed info about memory usage, performance, and many other things.
Just because I never turn down an opportunity to steer new programmers away from unityscript and boo, I'll strongly recommend C#. Very, very strongly. You'll thank me some day if you do. Or say "Man, that guy was right..." someday if you don't.
Good Luck moving forward and learning more about Unity,
Thanks ! It helped me a lot, yes i am still unfamiliar with many of the aspects of unity and game developing..thanks for helping...
and i know java much better than c# so should i go with java still? or turn my way to c#?
You're welcome! Glad to help. Please consider marking my answer as correct if you can.
C# is superior to UnityScript (aka Javascript) and Boo in too many ways to bother listing. It is strongly preferred by experienced programmers for these reasons. It offers features which are cumbersome (or just plain missing) in the other two languages. Furthermore, 100% of your C# skills will transition to non-Unity environments - the same isn't true of the other two.
Don't worry about making the switch during this project - you should stick with one language per project or headaches will happen. But next time around, try C#. It's not very hard to make the change, and the benefits are 110% worth it.
oh thanks, yes i have accepted your answer as correct as it helped me a lot..
Late answer to this question, but for #9, I have read that it's better to use compressed audio for longer audio such as background music and uncompressed audio for short/quick clicks and spells type SFX.
Great question as well as answer!
Your answer
![](https://koobas.hobune.stream/wayback/20220613165909im_/https://answers.unity.com/themes/thub/images/avi.jpg)