- Home /
help with reducing cpu usage
i have a problem with my script. when i run the game, my gamescript Update() is using a lot of cpu. i tried to reduce it a bit with some methodes but still a lot of cpu. GameScript
as you guys saw i have an online free database and the database works perfect but it uses a lot of cpu. i tried a methode that Update() only update every second but than you will see every second that some frames freezes. i really dont know how to reduce the gpu usage from my Update() in my gamescript while my script is still working. what this script does = getting data from the database, sums up those data to a total score. and than show the score in a textlabel.(btw i also have a script that is when i get a point it inserts it to the database(thats why i want it in update so the totalscore/highscore will stay updated)). i hope you guys can help me with reducing the script cpu usage or a better methode so i dont have fps lag. thanks in advance.
Answer by OusedGames · Oct 26, 2016 at 01:08 PM
Hello, I am noob about network, but if you are accessing it every frame, it will consume more network data isn't it? So update will cost a lot of network and cpu
I think you should get the online total score only on some circumstances like:
the game starts/ match starts/ on Game over/ on accessing leaderboard/ on game quit
Or run that in every 10 frames or fixed update
Hey OusedGames, first of all thanks for you reply and also sorry for a late respond. i tried yesterday to follow your 2nd advice. i tried with variables to only refresh it at it at the start of the game and at the end of the game(game over) and it worked. i also tried it on every 10 frames but it froze some other frames but your 2nd advice worked well. thanks for you help here is some example which code i used:
void Update () {// REFRESH AT START REFRESH AT DEATH REFRESH AT WIN
if ((PlayerController.IDied == false && Number == 0) || (PlayerController.IDied == true && Number <= 3) || (PlayerController.IWin == true && Number <= 3))
{
Number++;
The Code You Want To Repeat
Your answer
![](https://koobas.hobune.stream/wayback/20220612095443im_/https://answers.unity.com/themes/thub/images/avi.jpg)