Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Spiky Performance Issue

Discussion in 'Editor & General Support' started by markdeleon08, Jan 3, 2016.

  1. markdeleon08

    markdeleon08

    Joined:
    Nov 1, 2015
    Posts:
    17
    Hi Everyone,

    I have a very simple scene setup.
    - 2 Quads with material - mobile alpha blended (this is used for my background and ground).
    - Spawning Obstacles using object pooling.

    My obstacle has 2 collider and a rigidbody. Moving it using rigidbody2d.velocity.

    and my background and ground is scrolling using SetTextureOffset.

    my project quality settings is set to "fastest"(Vsync = dont sync).
    and in my script on Start i am setting the Application.targetFrameret to 60. and Qualitysettings.vSyncCount = 0.

    However, the game still lagging and when I try to profile it,
    It seems that the game is unstable and vSync is still On.
    CPU-
    Vsync = 10 - 16ms
    CPU Overview -
    WaitForTargetFPS = 12 - 15ms
    GPU-
    Other = 24 - 35ms
    GPU Overview -
    Camera.Render = 0.7ms

    Has anybody experience the same?
     
  2. Flavelius

    Flavelius

    Joined:
    Jul 8, 2012
    Posts:
    926
    Check your graphics driver for forced vsync. And profiling itself takes a hit on performance, so the results are not 100% like when the game runs without it. And targetFramerate is a framelimiter, which can be confused with vsync.
     
  3. markdeleon08

    markdeleon08

    Joined:
    Nov 1, 2015
    Posts:
    17
    Hi Valoo,
    I'm profiling with my android device. how can I check if forced vsync? and can we disable it?
    and also, what can you suggest for the setup when building games for android?
     
  4. Flavelius

    Flavelius

    Joined:
    Jul 8, 2012
    Posts:
    926
    Ah, sorry, i don't own an android device (yet), so i have no experience with those. But collision handling is somewhat costly in Unity, so i would expect a mobile device to be a little less performant. Also if you're using OnCollisionStay, that may as well be the source of the hickups (it's implemented via the slow SendMessage() internally). I would suggest to reverse your logic and move the player (one collider) instead of the obstacles (many colliders) and benchmark if it is faster.
     
  5. markdeleon08

    markdeleon08

    Joined:
    Nov 1, 2015
    Posts:
    17
    Hi Valoo, Thanks for replying.
    Hmm. What I did now was, I tried to recreate the project.
    Scene setup:
    - add 2 cubes for background and ground.
    - add materials on the cubes
    - add scripts to make it scroll using setTextureoffset.
    - Project Quality settings set to fastest
    - Create empty gameobject(gamecontroller) then add script which sets the vsync count to 0 and targetframerate to 60.
    - build and tried it on Android (Samsung Galaxy S4).

    - I'm still experiencing spiky performance.

    Any Ideas? :(
     
  6. Flavelius

    Flavelius

    Joined:
    Jul 8, 2012
    Posts:
    926
    Any other scripts? using GetComponent<>() every frame for example is expensive. Besides that, use the profiler to find slow functions.
    Edit: I found this, maybe it helps you too: "Before you build your apk go to the Android player settings, Other Settings, untick 'Auto Graphics API' and only add OpenGLES2 do not use 3 or even add it, its performance is terrible" (http://forum.unity3d.com/threads/ve...rading-to-unity-5.306572/page-11#post-2433520)
     
    Last edited: Jan 5, 2016
  7. markdeleon08

    markdeleon08

    Joined:
    Nov 1, 2015
    Posts:
    17
    Hi ValooFx,
    That seems to eliminate the performance issue. :)
    Thank you verymuch!