Hi all, here I’m to share my knowledge and difficulties that I faced during my game development using Unity. There are many apps already built by unity. Some of them did very good. PirateNinja shared his experience and we are very much thankful to him. We did finish our product development and doing the optimization. We divided the optimization in 3 phases:
Assets Optimization
Script Optimization
Physics Optimization
Unity Optimization [Different options that Unity is providing]
We already completed the 1st phase. Unity community one of the best community that I ever seen. We are expecting some valuable advice from this community to bring out product in stable phase. First we need to describe some settings that we are using.
It is a Open area navigation game. Sort of hill area. So, occlusion culling is not helping us.
For terrain collision we are using Mesh Collider. I know mesh collider is expensive, but if player come to ground touch in very rear case then isn’t it acceptable?
We used box collider most of the case for check point type cases.
There are some dynamic and small animating object. So, we can’t group them. SpriteManager can be a solution. We will see it in script optimization phase.
Only one Skinned Mesh.
First of all
we combined texture based on shared attribute and it is well organized.
we combined all static mesh as the vertex count is not exceeding 7K red line.
Here is some Xcode profile that can give a clear idea of it. iPhone 3G is our Device. Unity iPhone Advance is our License.
1st state after game enter in game scene
This after few seconds of the game play. Most of time we are getting this state.
This is the spike!!! This spike happen after few frame when player pass the check point. That mean when player pass the trigger collider. Listing 2 stats on hick-up.
After activating disabled game objects. Around 10-12 of them. Each object has an script attach with it and a tiny mesh.
We still have options to optimize, but the question is from where should we start? Which way will be optimal and effective? There are some great people in this forum and we are expecting some dictation and advice from them.
We can reduce the Physics time count by reducing Fixed Timer, we can gain some ms by using Fast No Exception and Byte Striping. I think it should be at the end.
Thanks in advance to all read this big post. All kind of opinion and advice greatly appreciated.
You know you posted on Saturday when traffic is lightest, right? Also your post contains a lot of data, but not much information.
You’ve accurately spotted the points in your game when the framerate drops. You know what scripts are running when those events occur (we don’t). You know you’re using a mesh collider and that is not recommended. You know that you could enable “fast and no exceptions” to possibly improve performance. And you know that it doesn’t seem to be rendering that is taking up most of the time in your app.
At least you read all of it and thanks a lot for the reply. I read that thread and I mentioned about Pirate Ninja in my post. Well, this is not all the same case. We have a physics dependency and if we make the Fixed Update to 1 then we have to write all physics simulation by ourself which is quite meaningless, isn’t it?
I gave lot of data and also gave the analysis of it, so that others can grasp the optimization steps [if it help :)].
I know the Mesh Collider is expensive but I mentioned why I used it. Here I have some query to understand the behind the scene. If any collider collide with another one then the cost of the physics start, right? If any collider collide with a Mesh Collider in very rear cases then why it should be costly?
My intention is to share the optimization steps and show the increased result by taking different technique. This is a case that totally depend on the game but it helps to start.
I already improved the performance and I will give some stats and analyzed data.
Its always costly once collideable things get near each other as the collision tests starts once you approach the point of collision. otherwise you never would detect a collision, as the collision / penetration is not detectable if you don’t have data from before and after to realize that your were “on the surface” in between.
But the spikes look more like a combination of physics combined with very badly written scripts that force a lot of GC collection.
String concatenation is a very good way to bomb the GC, but vector allocations (-> vector operations that return a new vector) are just as worse.
I don’t know this for sure, but my guess is that if you are inside the bounding volume of a mesh collider (even if you aren’t touching it) it still has to do some calculations (possibly visiting each triangle) to see if you are intersecting with any of the surface.
As I didn’t clean up the script yet, so it may be the culprit. Also, in the Pirate Ninja’s thread he mentioned that. I’m going through it now :). Thanks bro :). Another query is, String Concatenation is expensive and this is why we should use StringBuilder or Foramt, well and good, is the comparison is same expensive? We use the Tag and Layer to find the group or specific objects, is there any other way instead of useing Tag or Layer string comparison? While one object collide with another generally we check the tag or name to take action.
Thanks to clearing it out :). I will remove it defiantly but wanted to clear why it. I will give the state after Physics optimization.
Thanks again to all :). I will look forward for any kind of advice.
Just wanted to clarify, that I believe vector allocations don’t have the same penalty as strings; as they are created on the stack. Even doing “new Vector3()” will just allocate a value type (in this case struct) on the stack, that will get cleaned up as soon as the scope returns. Skipping all together the garbage collector, and the heap.