Hey guys I am new to Unity. This is also my first game engine that I’ve used. When doing the space shooter tutorial I noticed if I add 100 asteroids it can start feeling not very smooth. I also can kinda notice it when only have 10 asteroids flying by. Seems to be the same on pc build or web player build.
I’m only using the trailer version of the software at the moment is that why? I would of thought a simple asteroid game would be flawless with lag? Sent the build to a friend he said the same thing.
You could download the Pro trial and execute the project with the Profiler running, that should indicate you what’s consuming most resources.
I haven’t tried that tutorial but I suggest that you also investigate about pooling. IIRC in the manual there are other tips about improving performance. Remember that there’s no engine that can compensate for mistakes or lazy design, the programmer needs to be clever enough to use the resources available and nothing more.
One thing to remember about tutorials are that they are usually not performance oriented. I have found that most tutorials are not optimized unless its their focus. Trying to figure out why a tutorial is not performing very well can also help you be a better programmer.
This is one of the tutorials I didn’t write so I can’t help with any details about why it’s specifically not performing. However, this is a beginner tutorial and so I can make a few guesses. Our beginner tutorials are based on getting from nothing to making a game in the simplest way we can. As such they won’t usually include things like object pooling or any other optimisations. They are to help you understand the features of Unity and the basic structure of games made in Unity. Chances are in the space shooter tutorial gameobjects are being Instantiated and Destroyed rather than pooled. This is likely the source of the performance problem.
Kondor0 is absolutely correct about using the Profiler. It is an excellent way of determining what is slowing your game down. If you haven’t already tried it, I recommend getting a Pro Trail and giving it a go.
Oh ya true. I notice that the tutorial kept always remaking new asteroids instead of storing objects and reusing them. I have a large PHP/javascript background. If I wrote that in javascript I wouldn’t be recreating them each time.
If you write in Unity you typically don’t keep creating them either. It just requires some work to implement, so is left out of the beginner tutorials.
Still, pooling alone shouldn’t account for performance issues. There might be something else going on.
You wouldn’t happen to be using .FindComponent<> in updates would you? This would include using the .transform property directly. If you’re doing a lot of .transform.somethings, you may want to cache the transform (and any other finds you do) on the Start() of the script like so:
So you’ve got 100+ things moving around and it’s getting choppy? My first guess is that the moving objects don’t have Rigidbodies. I know it’s counter-intuitive, but adding Rigidbodies to moving objects makes them run faster. This is because of internal optimisations in the physics system - if it doesn’t have a Rigidbody it’s collision data is stored in an optimised collection that’s expected not to change, but if you then move the object that data has to be updated, which is expensive. You’re potentially doing that 100 times per frame.
If you don’t want physics to be applied set the Rigidbody to be “kinematic” and to not use gravity. Both are tick boxes in the inspector or available by code.