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
  4. Dismiss Notice

How to code to prevent mobile device get heated?

Discussion in 'Scripting' started by leegod, Mar 16, 2015.

  1. leegod

    leegod

    Joined:
    May 5, 2010
    Posts:
    2,343
    Some game running 5 minutes on mobile phone, device got heated and become hot to grab.

    When making mobile game, how to code to prevent phone becoming heated?

    So how to make code more thinner, light-weight?

    Thanks.
     
  2. Strategos

    Strategos

    Joined:
    Aug 24, 2012
    Posts:
    255
    It usually demanding graphics that cause over heating, try putting in quality options in your menu, low, medium and high for instance where you turn off effects, lower unities quality settings etc
     
  3. Kogar

    Kogar

    Joined:
    Jun 27, 2013
    Posts:
    80
    First. Unity is a 3d Engine and will always have more overhead compared to low level code or other 2d engines.
    In a more general direction on what to make better for optimized performance you have two sides to consider.
    The graphic side with a reduction of polygons texture sizes max gameobject count and animations. And everything i have forgotten to list to optimize GPU usage.
    The script side with everything that uses the CPU. Here you need to reduce function calls per frame.

    You could try to limit to 30 fps or lower when there is no animation playing. You could shortly ramp the fps up if needed ( http://docs.unity3d.com/ScriptReference/Application-targetFrameRate.html )

    Another big point is to prevent stuffing code into update().
    Only put necessary code like input control and other stuff that needs to react and update on each frame during the scripts whole lifetime into update().
    Everything else should be done with coroutines and events/delegates

    Following a few interesting links
    http://wiki.unity3d.com/index.php?title=General_Performance_Tips
    http://forum.unity3d.com/threads/state-machine-coroutine-vs-update.103110/
    http://unitypatterns.com/scripting-with-coroutines/
    http://www.theappguruz.com/unity/using-delegates-and-events-in-unity/
    http://www.paladinstudios.com/2011/11/11/animations-are-evil-performance-rules/
     
    petey and nvllap like this.
  4. leegod

    leegod

    Joined:
    May 5, 2010
    Posts:
    2,343
    Thanks much.
     
  5. GamesOn-Sahil

    GamesOn-Sahil

    Joined:
    Apr 22, 2021
    Posts:
    2
    Try using this in Update Function:

    private float lastCallTime;

    void Update()
    {
    if (Time.time - lastCallTime >=0.2){
    UpdateUI ();


    CarBlueprint c = cars [currentCarIndex];
    if (c.isUnlocked){
    amount.text = "".ToString ();
    }
    }
    }


    It will help to reduce function calls
     
  6. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    This won't work if you're not using cars :) You never assign a value to lastCallTime so UpdateUI would be called every time. And you generally want Unity to handle the UI. Please don't respond to 5 year old threads.
     
    ilievant and StarManta like this.