Search Unity

Reduce CPU and battery usage for a 2D Game

Discussion in '2D' started by Strooja, Jan 21, 2020.

  1. Strooja

    Strooja

    Joined:
    May 16, 2019
    Posts:
    26
    Hi Guys ,
    it is me again. I am building my first Game at the moment and I tried my beta version yesterday on my cellphone. After 30 minutes of playing my battery went from 42% to 5% . In my Game I don't have any physics and just 1-2 update functions.On top sometimes some InvokeRepeat functions.And sometimes I play a video.So nothing crazy at all.Can somebody tell me what I can do to reduce the cpu and battery usage.I talk more about global settings instead of changing code. I thought maybe it is possible to limit the frames or set a limit for the cpu usage . Has anyone some good advice,a website or a video to this topic? And another question is, is it better to play a video or should I split the video in single frames and play it as an animation??

    Thanks for your help
     
  2. Strooja

    Strooja

    Joined:
    May 16, 2019
    Posts:
    26
    No one with an idea?
     
  3. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,514
    You need to open up the Profiler and see what is consuming the most CPU. All else equal, eliminate InvokeRepeat because IIRC it uses reflection. You should just call the method itself or convert to doing the equivalent with a coroutine. But the profiler should help you decide if that's an important performance drain. It's difficult to say more without information from the profiler.

    General advice: https://learn.unity.com/tutorial/fixing-performance-problems
     
  4. Strooja

    Strooja

    Joined:
    May 16, 2019
    Posts:
    26
    great thank you very much for your help. I checked the profiler and it looks like that the vsync need the most of the cpu. I tried to limit it with 60 frames and disable vsync but then the game stutters. Is there anything else I have to change for the vsync .And is there another trick to reduce the battery usage(that the most important think) I guess the cpu usage is fine. Have between 100-400 frames.