Search Unity

Unexplainable lag in Android game

Discussion in 'Scripting' started by cabreak2, Oct 1, 2014.

  1. cabreak2

    cabreak2

    Joined:
    Jun 28, 2014
    Posts:
    14
    Hi everyone

    I have been debugging this bug for weeks but I couldn.t find anything that caused this random unexplainable lag.
    My 3D game on Android runs fine when I immediately move the player when the level starts.
    But if wait a couple of seconds (let's say 15 seconds, in these 15 seconds there is no lag at all) and I move the player just a bit, I get an incredible lag. I've tried to use the profiler but the spike looks to be randomly assigned to anything that happend that particular frame. Sometimes it's something very trivial, sometimes it's Physics.Simulate, just to be clear, it's purely random.

    An example of this:


    with the code:
    Code (CSharp):
    1.     void OnTriggerExit(Collider checkColl)
    2.     {
    3.         Profiler.BeginSample("@ JumpController.OnTriggerExit()");
    4.         if (checkColl.gameObject.CompareTag("MovingPlatform"))
    5.         {
    6.             isOnFixedPlatform = null;
    7.         }
    8.         Profiler.EndSample();
    9.     }
    10. }
    as you can see, the function OnTriggerExit in JumpController takes 157 ms to complete, while the code is trivial. Also notice the Profiler sample that doesn;t make any sense comparing it to the profiler.

    The one who can help me to fix this solution or explain this weird behaviour is a hero.

    Thanks!
     
  2. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,616
    should isOnFixedPlatform =null; be null or false.

    Its named like a boolean.. I assume you added the profiling stuff after you decided this was the problem? The GC alloc wont be helping.
     
  3. cabreak2

    cabreak2

    Joined:
    Jun 28, 2014
    Posts:
    14
    isOnFixedPlatform is a Gameobject. But yeah, you are right, I should change the name.
    And no, I often add Profiler samples while programming. Like I said before, it happens at random code in the scripts.