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.

Question Unity UI make whole game lag

Discussion in 'UGUI & TextMesh Pro' started by Flawless83, Nov 23, 2022.

  1. Flawless83

    Flawless83

    Joined:
    Dec 7, 2016
    Posts:
    122
    So i have a game with many players and a problem i get is that if i switch alot of players fast many times the game start to lag. I have to mention that i do have the player select menu on my start menu screen, so when i select a player and click play, the game start in the same scene.

    Can someon explain how the ui can make the whole game lag, i can play it without lag if i dont scroll thru to many players, but want to be able to scroll thru players to check what is there.

    It just dosnt make scence cause the game run at 30 fps but when i change players and fast it suddenly start to lag, and dont stop til i reload scene.

    Edit: Its on mobile and im using unity UI buttons.
     
  2. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    8,246
  3. Flawless83

    Flawless83

    Joined:
    Dec 7, 2016
    Posts:
    122
    i got litle over 80 players, well its actually throwable objects, i show code, the code is same for all so i just post 1. And it also only happens on mobile so cant use profiler.

    Code (CSharp):
    1.  public void RudderSelect()
    2.     {
    3.  
    4.  
    5.         FindPlayerInfoUI = GameObject.FindGameObjectsWithTag("SelectedIMG_PlayerSelectMenu_CameraCharacter");
    6.  
    7.         foreach (var playerObject in FindPlayerInfoUI)
    8.         {
    9.             playerObject.SetActive(false);
    10.         }
    11.  
    12.         CurrentCharacter = ES3.Load("currentCharacter", 2);
    13.  
    14.         if (CurrentCharacter != 2)
    15.         {
    16.             RudderSelectButton.SetActive(true);
    17.         }
    18.  
    19.         RudderOnClickIMG.SetActive(true);
    20.         RudderBigSelectMenu.SetActive(true);
    21.         RudderCameraCharacter.SetActive(true);
    22.  
    23.  
    24.     }
    25.  
    26.     public void RudderPlayerSelect()
    27.     {
    28.  
    29.  
    30.         ES3.Save("characterDisplay", 1);
    31.         ES3.Save("currentCharacter", 2);
    32.  
    33.         RudderOnClickIMG = GameObject.FindGameObjectWithTag("SelectedIMG_PlayerSelectMenu_CameraCharacter");
    34.         RudderOnClickIMG.SetActive(true);
    35.  
    36.         FindPlayerInfoUI = GameObject.FindGameObjectsWithTag("SelectedIMG_PlayerSelectMenu_CameraCharacter");
    37.  
    38.         foreach (var playerObject in FindPlayerInfoUI)
    39.         {
    40.             playerObject.SetActive(false);
    41.         }
    42.  
    43.         FindFramePlayer = GameObject.FindGameObjectsWithTag("FramePlayer");
    44.  
    45.         foreach (var playerObject in FindFramePlayer)
    46.         {
    47.             playerObject.SetActive(false);
    48.         }
    49.  
    50.         RudderFrameCamera.SetActive(true);
    51.         RudderSelectButton.SetActive(false);
    52.         SelectedPlayerV = GameObject.FindGameObjectWithTag("SelectedPlayerV");
    53.         SelectedPlayerV.SetActive(false);
    54.         RudderOnClickIMG.SetActive(true);
    55.         RudderBigSelectMenu.SetActive(true);
    56.         RudderCameraCharacter.SetActive(true);
    57.         DeactivatePlayer =  GameObject.FindGameObjectWithTag("Player");
    58.         RudderSelectedPlayerV.SetActive(true);
    59.         DeactivatePlayer.SetActive(false);
    60.         RudderPlayer.SetActive(true);
    61.         CheckPremiumPlayerInfo();
    62.  
    63.  
    64. }
    65.  
    66.     public void RudderBuySelect()
    67.     {
    68.         if (TotalGold >= RudderPurchaseValue)
    69.         {
    70.             RudderBuyConfirmUI.SetActive(true);
    71.         }
    72.         else
    73.         {
    74.             RudderNotEnoughGoldUI.SetActive(true);
    75.         }
    76.    
    77.     }
    78.  
    79.     public void RudderBuyConfirm()
    80.     {
    81.         if (TotalGold >= RudderPurchaseValue)
    82.         {
    83.  
    84.  
    85.             FindPlayerInfoUI = GameObject.FindGameObjectsWithTag("SelectedIMG_PlayerSelectMenu_CameraCharacter");
    86.  
    87.             foreach (var playerObject in FindPlayerInfoUI)
    88.             {
    89.                 playerObject.SetActive(false);
    90.             }
    91.  
    92.             FindFramePlayer = GameObject.FindGameObjectsWithTag("FramePlayer");
    93.  
    94.             foreach (var playerObject in FindFramePlayer)
    95.             {
    96.                 playerObject.SetActive(false);
    97.             }
    98.  
    99.             RudderFrameCamera.SetActive(true);
    100.             SelectedPlayerV = GameObject.FindGameObjectWithTag("SelectedPlayerV");
    101.             SelectedPlayerV.SetActive(false);
    102.             RudderSelectedPlayerV.SetActive(true);
    103.             TotalGold -= RudderPurchaseValue;
    104.  
    105.             ES3.Save("Gold", TotalGold);
    106.             ES3.Save("characterDisplay", 1);
    107.             ES3.Save("rudderPurchased", 2);
    108.             ES3.Save("currentCharacter", 2);
    109.  
    110.             currency.ChangeCurrencyValue();
    111.             RudderSelectButton.SetActive(false);
    112.             RudderBuyButton.SetActive(false);
    113.             RudderBuyConfirmUI.SetActive(false);
    114.             RudderOwnedPlayer.SetActive(true);
    115.             DeactivatePlayer = GameObject.FindGameObjectWithTag("Player");
    116.             DeactivatePlayer.SetActive(false);
    117.             RudderPlayer.SetActive(true);
    118.             RudderOnClickIMG.SetActive(true);
    119.             RudderBigSelectMenu.SetActive(true);
    120.             RudderCameraCharacter.SetActive(true);
    121.             CheckPremiumPlayerInfo();
    122.  
    123.  
    124.         }
    125.     }
    126.  
    127.     public void RudderNotEnoughGold()
    128.     {
    129.         RudderNotEnoughGoldUI.SetActive(false);
    130.         PlayerMenuUI.SetActive(false);
    131.         PurchaseCurrency.SetActive(true);
    132.     }
    133.  
    134.     public void RudderCheckInfo()
    135.     {
    136.         CurrentCharacter = ES3.Load("currentCharacter", 2);
    137.         RudderPurchased = ES3.Load("rudderPurchased", 1);
    138.         CharacterDisplay = ES3.Load("characterDisplay", 1);
    139.  
    140.         //Remember To Change Character Value
    141.  
    142.         if (CurrentCharacter == 2)
    143.         {
    144.             SelectedPlayerV = GameObject.FindGameObjectWithTag("SelectedPlayerV");
    145.             SelectedPlayerV.SetActive(false);
    146.             RudderSelectedPlayerV.SetActive(true);
    147.             RudderOnClickIMG.SetActive(true);
    148.             RudderSelectButton.SetActive(false);
    149.             RudderBigSelectMenu.SetActive(true);
    150.             RudderCameraCharacter.SetActive(true);
    151.             DeactivatePlayer = GameObject.FindGameObjectWithTag("Player");
    152.             DeactivatePlayer.SetActive(false);
    153.             RudderPlayer.SetActive(true);
    154.             BeeBigSelectMenu.SetActive(true);
    155.             BeeCameraCharacter.SetActive(true);
    156.             BeeSelectButton.SetActive(true);
    157.             BeeOnClickIMG.SetActive(true);
    158.             RudderFrameCamera.SetActive(true);
    159.         }
    160.         else
    161.         {
    162.             RudderSelectButton.SetActive(true);
    163.         }
    164.  
    165.         //Value Is 2 For True
    166.  
    167.         if (RudderPurchased == 2)
    168.         {
    169.             RudderBuyButton.SetActive(false);
    170.             RudderOwnedPlayer.SetActive(true);
    171.         }
    172.  
    173.     }

    this is the code i post a picture so you can see how the ui look like.

    MenuUiPlayer2.png

    so if i click the buttons on the left while spaming the select button in the right many times the framerate drops so much. And it dosnt ge fixed until i restart scene in the game, but then i can start it again and all lag is gone. also like to add that i use 3d model projected to texture for the icons.

    Edit: so i removed the 3d models from the image leaving only the texture, and now i cant seem to reproduce the lag problem, is using lots of render texture not good, i do delete the whole playerui when i start the game so weird that it lags after deleting the models and the textures and the whole playerui?
     
    Last edited: Nov 23, 2022