Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

Low fps while moving sprites

Discussion in 'Scripting' started by ycanatilgan, May 24, 2020.

  1. ycanatilgan

    ycanatilgan

    Joined:
    Aug 23, 2017
    Posts:
    6
    Hi,
    I’m developing small 2d game for mobile, and I need sprites to drop from sky. But when I do this, they look like 20-25 fps even though editor shows ~500 fps. I tried different methods to move them; transform.Translate, using gravity/rigidbody...

    However they still dont look smooth. What might be the problem?
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    1,105
    Are you using rigidbodies? You might need to turn on interpolation.
     
  3. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    1,223
    If it's not interpolation, please check the Profiler.
    The FPS shown by the editor is an average. 500 FPS with stable frametimes (ie about 2.5ms per frame) would be smooth. However, the value 500 doesnt tell you a lot about whether or not your game is perceived as smooth. You may as well generally have frame times of 1ms, with huge spikes a couple times a second, averaging the frame times at around 2.5ms. This would show you 500 FPS, but would be perceived as stuttery by the average person.
     
  4. ycanatilgan

    ycanatilgan

    Joined:
    Aug 23, 2017
    Posts:
    6
    Adding rigidbody component again and enabling interpolation didn't helped :(

    My stats are like this:
    unnamed.png

    And now I opened up my profiler but didn't understand it much.
    unnamed1.png

    Also
    unnamed.png

    Edit: Now I created a new blank project and tried to give them gravity scale to see if it is my fault; but guess what? It is still the same on even a blank project! Just one sprite and its gravity; no canvas, no scripts.
     
    Last edited: May 24, 2020
  5. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    627
    The FPS shown in the game view stats is calculated using only the Player loop time, ignoring the EditorLoop time, but the actual FPS you see is based on both times combined because they run on the same thread. I.e. the EditorLoop might induce a stutter.

    Some of the spikes in your Profiler screenshot are going to be caused by the Profiler window repainting itself. Try making a build and see if you see the stutter there and if so, profile that build. Also check the profiler manual pages for info on how to use it.

    It'd also be relevant to know how you move the sprites, i.e. via Transform or rigidbody and if you do so in Update or FixedUpdate
     
  6. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    627
    I can see you're using 2019.3 or a later version if you are on 2020.1 you can also start the Standalone Profiler to profile the editor without the Profiler window impacting the EditorLoop
     
  7. ycanatilgan

    ycanatilgan

    Joined:
    Aug 23, 2017
    Posts:
    6
    Already built an apk file (actually multiple times) and the result was unfortunately the same :( I tried to move them by using gravity scale and transform.Translate however result was the same for both. Im using 2019.3.14.

    The most interesting thing I encountered is having this issue on even a blank project! I just added a sprite and gave it gravity scale! Still not that smooth.
     
    Last edited: May 24, 2020
  8. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    627
    Did you profile that Android build?

    Also, what does the code look like with which you move the sprite?
     
  9. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    1,223
    The screenshot you posted seems to be slightly before the spike. It would be useful to know what's going on at the center of the spike. These spikes are what cause your stutter. Profile them and see what happens there that eats up this much time. Then fix it and your stutter will be gone.
     
unityunity