Hi folks. I am making my first game, and can’t defeat this issue. When level get started and u began move, the game start lagging few times, and everytime at the same position, but different for each level. After few trying, the level start working fine. I made everithing to make levels much lighter, but it doesn’t help. So here is little bad quality (nokia) video that replicate issue:
https://vimeo.com/19104068
The most interesting, thet game dont lag on ipod 2-nd generation, but lag on older models. On Retina display it’s look perfect with high resolution and very very responsive with gyro, but this lags at the begining killing all my work
I began to use FixedUpdate function instead Update, but it steel laging at first in the begining of each level.
No one can tell you the exact problem without seeing the actual code it can be anything, but if you’re using unity pro, i suggest you to use the PROFILER and search for any bottlenecks.
I has remove all scripts. Leave only one, that moving character by pressing areas on the screen and firing only this code. Nothing else.
var controller : CharacterController = GetComponent(CharacterController);
flags = controller.Move(moveDirection300Time.deltaTime/scale);
I remove skybox and the result is still the same. After loading level it is lagging at first few times, but then working fine (Like on video). When i am lagging, internal profiles show:
End Load File completely 3897.954708
iPhone Unity internal profiler stats:
cpu-player> min: -4947.3 max: 9357.1 avg: 162.3
cpu-ogles-drv> min: 0.6 max: 4996.1 avg: 175.6
cpu-present> min: 0.6 max: 11.5 avg: 2.2
frametime> min: 31.5 max: 9389.6 avg: 350.0
draw-call #> min: 11 max: 60 avg: 55 | batched: 0
tris #> min: 210 max: 15238 avg: 13736 | batched: 0
verts #> min: 332 max: 7814 avg: 7066 | batched: 0
player-detail> physx: 4.4 animation: 0.0 culling 0.5 skinning: 0.0 batching: 0.0 render: 12.0 fixed-update-count: 1 … 17
mono-scripts> update: 0.9 fixedUpdate: 0.5 coroutines: 4.1
mono-memory> used heap: 405504 allocated heap: 479232 max number of collections: 0 collection total duration: 0.0
iPhone Unity internal profiler stats:
cpu-player> min: -1052.1 max: 860.7 avg: 21.2
cpu-ogles-drv> min: 4.2 max: 1099.6 avg: 65.2
cpu-present> min: 0.8 max: 2.7 avg: 1.5
frametime> min: 32.8 max: 1148.1 avg: 93.3
draw-call #> min: 34 max: 64 avg: 56 | batched: 0
tris #> min: 9076 max: 16186 avg: 14313 | batched: 0
verts #> min: 4668 max: 8298 avg: 7342 | batched: 0
player-detail> physx: 5.2 animation: 0.0 culling 0.6 skinning: 0.0 batching: 0.0 render: 11.3 fixed-update-count: 1 … 17
mono-scripts> update: 1.0 fixedUpdate: 2.9 coroutines: 0.0
mono-memory> used heap: 339968 allocated heap: 479232 max number of collections: 0 collection total duration: 0.0
iPhone Unity internal profiler stats:
cpu-player> min: -317.0 max: 280.3 avg: 20.5
cpu-ogles-drv> min: 2.0 max: 340.3 avg: 40.2
cpu-present> min: 0.4 max: 2.2 avg: 0.7
frametime> min: 30.1 max: 362.7 avg: 72.3
draw-call #> min: 20 max: 34 avg: 23 | batched: 0
tris #> min: 4537 max: 9076 avg: 5426 | batched: 0
verts #> min: 2317 max: 4668 avg: 2776 | batched: 0
player-detail> physx: 4.8 animation: 0.0 culling 0.3 skinning: 0.0 batching: 0.0 render: 5.6 fixed-update-count: 1 … 17
mono-scripts> update: 1.1 fixedUpdate: 7.0 coroutines: 0.0
mono-memory> used heap: 352256 allocated heap: 479232 max number of collections: 0 collection total duration: 0.0
iPhone Unity internal profiler stats:
cpu-player> min: -351.7 max: 395.2 avg: 20.9
cpu-ogles-drv> min: 2.0 max: 525.7 avg: 78.8
cpu-present> min: 0.4 max: 6.9 avg: 1.3
frametime> min: 31.8 max: 578.9 avg: 109.9
draw-call #> min: 20 max: 64 avg: 36 | batched: 0
tris #> min: 4537 max: 16186 avg: 8946 | batched: 0
verts #> min: 2317 max: 8298 avg: 4583 | batched: 0
player-detail> physx: 5.1 animation: 0.0 culling 0.4 skinning: 0.0 batching: 0.0 render: 7.6 fixed-update-count: 1 … 17
mono-scripts> update: 1.3 fixedUpdate: 4.8 coroutines: 0.0
mono-memory> used heap: 385024 allocated heap: 479232 max number of collections: 0 collection total duration: 0.0
iPhone Unity internal profiler stats:
cpu-player> min: 17.0 max: 218.2 avg: 77.7
cpu-ogles-drv> min: 5.8 max: 11.8 avg: 8.8
cpu-present> min: 0.8 max: 5.5 avg: 1.6
frametime> min: 32.8 max: 231.0 avg: 92.2
draw-call #> min: 52 max: 61 avg: 54 | batched: 0
tris #> min: 13342 max: 15475 avg: 13997 | batched: 0
verts #> min: 6846 max: 7935 avg: 7180 | batched: 0
player-detail> physx: 5.4 animation: 0.0 culling 0.5 skinning: 0.0 batching: 0.0 render: 11.3 fixed-update-count: 1 … 12
mono-scripts> update: 0.8 fixedUpdate: 58.1 coroutines: 0.0
mono-memory> used heap: 454656 allocated heap: 479232 max number of collections: 0 collection total duration: 0.0
iPhone Unity internal profiler stats:
cpu-player> min: 14.8 max: 25.4 avg: 19.2
cpu-ogles-drv> min: 6.3 max: 11.9 avg: 9.1
cpu-present> min: 0.9 max: 6.1 avg: 1.8
frametime> min: 31.8 max: 44.8 avg: 35.7
draw-call #> min: 48 max: 65 avg: 55 | batched: 0
tris #> min: 12394 max: 16423 avg: 14258 | batched: 0
verts #> min: 6362 max: 8419 avg: 7313 | batched: 0
player-detail> physx: 4.3 animation: 0.0 culling 0.5 skinning: 0.0 batching: 0.0 render: 10.3 fixed-update-count: 1 … 2
mono-scripts> update: 0.9 fixedUpdate: 2.3 coroutines: 0.0
mono-memory> used heap: 417792 allocated heap: 479232 max number of collections: 0 collection total duration: 0.0
That’s all i have
Did you say you are using unity iphone 1.7? I would suggest switching to unity 3. It supports iphone, android, xbox, everything in one program. Just make sure you back up your files before switching over. You will have to reapply all your textures and reasign your scripts and maybe a few other things, once you import your project into unity 3. Dont make the same mistake i did and simply open your current project in unity 3. It will automatically update your project and will mess everything up if you want to go back to unity iphone 1.7. If you still have your serial key for unity iphone 1.7, you should be able to use that unlock all of the iphone features in unity 3.
http://forum.unity3d.com/threads/69022-Is-the-iOS-basic-in-the-unity-store-version-1.7
I dont know if it’ll clear up your lag issues, but it always helps to be using the latest software.
Thx Eteeski, but Unity 3 have a big issue with occlusion culling, and i can not use it. I can create view areas, but they do not work like view areas in Unity iPhone 1.7. So i am back to 1.7. Maybe the problem is that level or oclusion dont load completely, and you need run some script to initialize all scene?
I found the reason why lagging. When i disable all PointLight in the scene, all works fine. How can i solve this? What can be the problem of lagging with light? Can i generate whole lightmap and disable all light? All planes use this script to make material look the same on different planes with different size:
var scale : float = 3;
private var scaleX : float;
private var scaleY : float;
scaleX = scale;
scaleY = scale;
function Start ()
{
for (var i = 0; i < renderer.materials.Length; i++) {
renderer.materials_.mainTextureScale = Vector2 (transform.localScale.x * scaleX, transform.localScale.z * scaleY); _