Search Unity

My game lags in Android

Discussion in '2D' started by Giannigiardinelli, Apr 7, 2020.

  1. Giannigiardinelli

    Giannigiardinelli

    Joined:
    May 8, 2014
    Posts:
    189
    Hello

    I finally finalized my game for Android and with the luck I have!
    It is not working properly. I have a tablet (Galaxy Tab E) and my game, but way too much time to throw and lag when navigating the game!
    The worst part is that there is no 3d Object!
    I can't even imagine, if I had put it on!
    My game is simple and works with Unity's UI feature!
    It's all in 2D and works with Canvas Image! + ADS !!

    I do not understand why the game lags on Android !?



    On my PC it works, but when I test on the tablet it takes time to load!
    I put the Statistics in picture, but my "Batches" of my stats is only 29!


    I've been researching the forums on the current problem. I followed the advice to put my GameObject in Static and uses the function of the code "SceneManager.LoadSceneAsync" but still the same when loading on Android ...
    (For the record I only used two scenes, because the game simply works with images!)

    Could someone help me make it more fluid on Android?
    I was ready to publish the game, but if it just lags on tablet and phone. No one will play it if the game takes 3 minutes to throw!

    Thanks in advance for your help !
     
  2. Chris-Trueman

    Chris-Trueman

    Joined:
    Oct 10, 2014
    Posts:
    1,261
    GUI.Repaint tells me you are using OnGUI calls. Avoid them at all cost, they are for in the editor.
    Its also generating 1.1kb of garbage every frame which can kill performance on mobile.

    Other than that, with SetPass calls only being 2 its not a draw call issue. (Batches are not draw calls the SetPass calls are. You can check this with the frame debugger.)

    It could be due to overdraw, if you have a lot of transparency.

    Without a project, I can only make assumptions.
     
  3. Giannigiardinelli

    Giannigiardinelli

    Joined:
    May 8, 2014
    Posts:
    189
    Hi Chris
    Thank you for your reply and coming to my rescue!

    The current problem and I do not understand the table "Profiler" and do not understand everything that has marked in the statistics! Hence the reason for my misunderstanding of the problem I have today!

    What I can say and answer to you is that I do not use the OnGUI function!
    That's what's strange!

    On the other hand, i can you say I only use the
    • "UI" functions of the
    • "Sprite" of "List" or SpriteRender,
    • Random.Range and a lot of
    • Gameobject.Setactive for the functionality of the menu ...

    The only problem I thought about afterwards is that my project is virtually sure "one" scene. For the reason I didn't think that a simple game like that could lags.

    Do I have to review my scripts? If I understood correctly the "CPU" should not be at 1ms and also the same for the "GPU"?
    The CPU is about everything coding? And GPU all that is graphic?

    What solution can I bring to improve my game, without starting all over again?

    Thanks in advance for your help!!
     
  4. Chris-Trueman

    Chris-Trueman

    Joined:
    Oct 10, 2014
    Posts:
    1,261
    Maybe an asset you downloaded or a package is using it. Check in on that GUI.Repaint in the profiler and see where it might be coming from. You might need to set it to deep profile.
     
  5. Giannigiardinelli

    Giannigiardinelli

    Joined:
    May 8, 2014
    Posts:
    189
    Ok, I'll look at that. But I didn't download anything in my game... The games only use that "UI" with "Sprite" images... A simple game, which is built only with images !! this disgusts me with unity3d how that it can be in lags!
    thx
     
  6. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,456
    What version of Unity is that? 5.6? You might want to update to a version that is still supported, e.g. 2017 or 2018 LTS.

    Also I assume the screenshot is not from the Profiler profiling your device because 1ms frame time means you're very much in the clear. Please consult the documentation on how to profile the app running on a device and check what is happening there.
     
  7. Giannigiardinelli

    Giannigiardinelli

    Joined:
    May 8, 2014
    Posts:
    189
  8. Giannigiardinelli

    Giannigiardinelli

    Joined:
    May 8, 2014
    Posts:
    189
    Yes that's right! I'm 5.6 Unity, How do you know that? I'll see what I can do thank you @MartinTilo

    I'll see for the version of Unity but the problem is that the new version does not have the same functionality and does not like at all what unity has become! It's incomprehensible! Why is it a problem to be on a version like the one I have?
     
  9. Giannigiardinelli

    Giannigiardinelli

    Joined:
    May 8, 2014
    Posts:
    189
    Here's the profiler when I launch the project. My tablet is connecting with unity and here in pictures the profile the app running... For the second scene, she's not launch! I try to launch my second scene directly on my tablet with the profiler connect! Problem! My console displays "Warning"

    I'm saturating of Unity3D
     

    Attached Files:

  10. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,456
    Working on the Profiler Window, I know roughly how the UI looks in each version and in this one, Others is still yellow.

    The Unity version itself might not be a problem but always interesting to know in these cases, e.g to know which performance improvements or bugfixes it contained and which version of the UI. If this would've looked more like a bug with Unity, updating to an LTS would've possibly included a fix for such a bug. As it stands now with the device data, it seems to just be your coroutines running wilde on the device.

    So investigate those Coroutine Delayed calls.

    Also, if you need more details in your coroutines, you might want to wrap some code in there in Profiler.BeginSample() .EndSample () calls.

    Regarding the warning, I think it's rather clear in what it is trying to tell you and it spamming the console means its also spamming in the build and might affect prefomance (if its more than the 7, like in the hundreds) as well so you might want to do what it says to fix that.

    Lastly, I know debugging and fixing performance issues can be frustrating but try to keep your patience. It's rather unlikely that anyone reading this thread or answering, trying to help you, is responsible for the issues you're having.
     
  11. Giannigiardinelli

    Giannigiardinelli

    Joined:
    May 8, 2014
    Posts:
    189
    After an hour, I managed to record the profile statistics of my 2nd scene, here after correcting the problems of "Warning" Here is the display of the profiler connect to my tablet for the 2nd scene!
     

    Attached Files:

  12. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,456
    Did you investigate your Coroutines from the first scene? They looked rather bad.

    In that second scene, the last frame that you're showing seems to have some issues (the ProcessInput part and the unaccounted time. Unaccounted time samples are bugs where someone forgot to instrument some part in the player loop. I'd guess that's fixed in newer Unity versions.) But I can't tell why without context.

    Asides from that, seems like the remaining frames are mostly hitting 30 fps and spend their time rendering (possibly just waiting for the target fps/vsync) but you'd have to select those to see what took them 33ms. Same for those spikes. I can't tell anything from this graph.

    Please also read through the Profiler documentation and check the section on common samples (the 2019.3 documentation is the most comprehensive and I hope most of this didn't change since 5.6)
     
  13. Giannigiardinelli

    Giannigiardinelli

    Joined:
    May 8, 2014
    Posts:
    189
    The first scene is only a loading scene to see the time of the load of my 2nd with the code (SceneManager.LoadSceneAsync) that's why my scene is also very bad, because it loads my game from the 2nd scene! (My whole game is based on the second scene) one of my project mistakes. but i Don't think of such a big lag!

    I'll test see other version of unity3d on another pc on will see well but I'm very sad about all this housekeeping!

    I'll try to see if I can send you more images with a better detail of the profiler! Tell me what exactly you want to see if you don't mind? Thanks again to you and other person who could possibly help me!

    What disgusts me is that all the time I devote teaches me new things yes... But I think I'm in a situation where I'm going to have to re-arrange my scenes to be able to move forward again. I made mistakes yes but very disappointed of the software of unity3d for a game with only (sprites) and that does not exceed the GB!
     
  14. Giannigiardinelli

    Giannigiardinelli

    Joined:
    May 8, 2014
    Posts:
    189
    I would add that the problem does not come from the tablet. Because it is empty and I think for a Galaxy Tab E tablet it is largely recent for it to work properly. Especially since I test games like Ubisoft in 3d that works great!
    Thank you for the people who takes the time to help me!
     
  15. Giannigiardinelli

    Giannigiardinelli

    Joined:
    May 8, 2014
    Posts:
    189
    here are graphic images of the profiler of my first test scene on the loading of the game!
     

    Attached Files:

  16. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,456
    You should disable these Debug.Logs in your TestLoading.AsynchronousLoad coroutines. They are generating too much garbage allocations, and triggering GC.Collect which is going to stall everything. Also use yield return null; instead of yield return new WaitForEndOfFrame();
    Are you expecting to see this many instances of the coroutine? Are you starting too many? Are you starting them recursively? Are you ever ending them (getting to the end of the scope or a yield return break) or calling StopCoroutine for any of them. Do you maybe have an endless loop in them?

    Just select frames with bad performance and see what Hierarchy view and in case of Rendering times being bad also what Timeline View (showing the interplay between main and render thread) show for these. In hierarchy view, focus on the worst offenders.

    Making games is hard and Unity makes it a whole lot easier, sadly to the point where it is super easy to solve things in very sub-optimal ways if you don't know what you're doing. It's a focus for newer versions of Unity to guide towards better practices but ultimately, you'll always need some experience and focus on performance, especially if you're targeting low end devices like phones and tablets. Ubisoft and Co have large and very experienced teams to achieve what they do.
     
  17. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,456
    Also one thing to maybe look out for is that some ads SDKs like Google AdMob can have significant performance impacts. You could try turning ads of to see if that helps. And if you're animating elements on your uGui canvases, you're likely dirtying their layout every frame which is also expensive because it has to be recalculated. But I can't tell if that's your issue without seeing more details ;)
     
  18. Giannigiardinelli

    Giannigiardinelli

    Joined:
    May 8, 2014
    Posts:
    189
    Thank you very much @MartinTilo for your patience and your help on my problem!

    I will disable the Debug.Log

    I had to use this method compared to the delays of launching my game ...

    OK, I turn off "DebugLog" to remove GC. Collect!
    Here are my Coroutines: I have two scripts that use this feature...

    LoadingScript :

    Code (CSharp):
    1.     void Start () {
    2.      
    3.     }
    4.  
    5.     // Update is called once per frame
    6.     void Update()
    7.     {
    8.         CounterSceneSuivante += Time.deltaTime * 1;
    9.  
    10.         if (CounterSceneSuivante > 10f)
    11.         {
    12.  
    13.             ActiveScene = true;
    14.  
    15.         }
    16.  
    17.         if (ActiveScene)
    18.         {
    19.  
    20.             StartCoroutine(AsynchronousLoad("GuessCelebrity"));
    21.  
    22.         }
    23.     }
    24.  
    25.     IEnumerator AsynchronousLoad(string GuessCelebrity)
    26.     {
    27.         yield return null;
    28.  
    29.         AsyncOperation ao = SceneManager.LoadSceneAsync("Scene01");
    30.         ao.allowSceneActivation = false;
    31.  
    32.         while (!ao.isDone)
    33.         {
    34.          
    35.             float progress = Mathf.Clamp01(ao.progress / 0.9f);
    36.             TextCharge.text = "" + (progress * 100) + "%";
    37.             //Debug.Log("Loading progress: " + (progress * 100) + "%");
    38.  
    39.             // Loading completed
    40.             if (ao.progress == 0.9f)
    41.             {
    42.                 ao.allowSceneActivation = true;
    43.             }
    44.  
    45.             yield return null;
    46.         }
    47.     }
    and ADSManager :

    Code (CSharp):
    1. public class ADSManagers : MonoBehaviour {
    2.     public Text rewardText;
    3.     private int rewardCount = 0;
    4.  
    5.     private string gameId = "";
    6.  
    7.     string placementId_video = "video";
    8.     string placementId_rewardedVideo = "rewardedVideo";
    9.  
    10.     private bool testMode = true;
    11.  
    12.     // Use this for initialization
    13.     void Start () {
    14.  
    15.         if (Application.platform == RuntimePlatform.IPhonePlayer)
    16.             gameId = "";
    17.         else if (Application.platform == RuntimePlatform.Android)
    18.             gameId = "";
    19.  
    20.         Monetization.Initialize(gameId, testMode);
    21.     }
    22.  
    23.     public void ShowAd()
    24.     {
    25.         StartCoroutine(WaitForAd());
    26.     }
    27.  
    28.     public void ShowRewardedAd()
    29.     {
    30.         StartCoroutine(WaitForAd(true));
    31.     }
    32.     IEnumerator WaitForAd(bool reward=false)
    33.     {
    34.         string placementId = reward ? placementId_rewardedVideo : placementId_video;
    35.         while (!Monetization.IsReady(placementId))
    36.         {
    37.             yield return null;
    38.         }
    39.  
    40.         ShowAdPlacementContent ad = null;
    41.         ad = Monetization.GetPlacementContent(placementId) as ShowAdPlacementContent;
    42.  
    43.         if (ad != null)
    44.         {
    45.             ad.Show(AdFinished);
    46.         }
    47.     }
    48.  
    49.     void AdFinished(ShowResult result)
    50.     {
    51.         if (result == ShowResult.Finished)
    52.         {
    53.             // Reward the player
    54.             rewardCount++;
    55.             rewardText.text = rewardCount.ToString();
    56.         }
    57.     }
    58.     // Update is called once per frame
    59.     void Update () {
    60.      
    61.     }
    62. }
    The further I go, the more I learn in this performance fight that finally I start to believe that the problem comes from writing my scripts! It's a lot further than I think...


    It's always the same again... I have you sent here several screenshots of Timeline and the Hirarchie where she climbs to the top of the game ...

    Tell me what you think... Thank you again...
     

    Attached Files:

  19. Giannigiardinelli

    Giannigiardinelli

    Joined:
    May 8, 2014
    Posts:
    189
    and other again
     

    Attached Files:

  20. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,456
    Alright so the issue with the Coroutines is rather simple: You are starting one Coroutine per frame after 10 seconds.
    Code (CSharp):
    1. bool startedLoading;
    2.     void Update()
    3.     {
    4.         if(startedLoading)
    5.                return;
    6.         CounterSceneSuivante += Time.deltaTime * 1;
    7.         if (CounterSceneSuivante > 10f)
    8.         {
    9.             ActiveScene = true;
    10.         }
    11.         if (ActiveScene)
    12.         {
    13.              startedLoading = true;
    14.             StartCoroutine(AsynchronousLoad("GuessCelebrity"));
    15.         }
    16.     }
    I'll ignore the very first frame here because to optimize start-up time I'd need to know way more about your project than just Profiler screenshots and I want to just focus on smooth gameplay here.

    For the timeline screenshots, it'd be more interesting to see the entire frame, from vertical line to vertical line. One thing I can see is that your not using multithreaded rendering. Not sure if that was available in 5.6 for Android but maybe something to investigate for you, if that would improve performance.

    Now what GameObject are you activating in those frame spikes? I'd guess a canvas with quite a few maskable graphics and a complex Animator component on it? If you repeatedly switch between showing one set of things and another, you could try to have them all activitate already at the start of the scene and hide them off screen or setting some crutial components as disabled so they won't render but so that re-enabling of only these components could be cheaper.

    Also Options.Update() seems to be setting quite a few GameObjects active and inactive, possibly every frame costing you 1ms. Check if that's really necessary.

    Try playing around with reducing the complexity of whatever GameObject your activating, be it it's Transform hierarchy, the Animator setup, the maskable graphics or whatever else is on there and observe the effect in the Profiler. That should help you inform how to tackle this best.
     
  21. Giannigiardinelli

    Giannigiardinelli

    Joined:
    May 8, 2014
    Posts:
    189
    As I understand it @MartinTilo , do I have to review all my scripts?

    This is not a piece of play that I have to change, but rather the whole game! I am broken and very sad to hear that.
    Here are some of the scripts I suspect of lags from my game and what I understood from MartinTilo, I also respond to @JxWolfe...

    My game menu is made of "GameObject" which I disable and activate when the player clicks a button...

    Example: The player clicks the Option button >>

    GameObject_Option.Setactive (true) WindowsMenu = False "and" When the player clicks to close >>

    GameObject_Option.Setactive (false) WindowsMenu = true etc... On my menu!


    After in the game function. I use an Image List (Sprite) that calls for a "Random" Code... The player clicks "Play" and script is looking for a random image... Virtually the whole game uses these script explain above.


    Look my image for example


    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine.UI;
    4. using UnityEngine;
    5.  
    6.  
    7. public class Options : MonoBehaviour {
    8.  
    9.     [Header("Appel Script")]
    10.     public Dropdown OptionChanson;
    11.     public GameObject ObjectChanson;
    12.     public Toggle OptionToggle;
    13.     public GameObject ObjectToggle;
    14.  
    15.     [Header("Fenetre Option")]
    16.     public Dropdown DropLangue;
    17.     public GameObject DropDown;
    18.     public GameObject FenetreIndisponible;
    19.  
    20.     [Header("Option Sound")]
    21.     public GameObject OnMusic;
    22.     public GameObject On;
    23.     public GameObject Off;
    24.  
    25.     [Header("GameObject Music")]
    26.     public GameObject SoundStar;
    27.     public GameObject SoundsMuser;
    28.     public GameObject SoundsNights;
    29.     public GameObject SoundsVirgos;
    30.     public GameObject SoundsFollowYourHeart;
    31.  
    32.     [Header("GameObject Fr")]
    33.     public GameObject[] TextFr;
    34.     public GameObject[] TextEn;
    35.     // Use this for initialization
    36.     void Start () {
    37.  
    38.         OptionChanson = ObjectChanson.GetComponent<Dropdown>();
    39.         OptionToggle = ObjectToggle.GetComponent<Toggle>();
    40.         DropLangue = DropDown.GetComponent<Dropdown>();
    41.     }
    42.    
    43.     // Update is called once per frame
    44.     public void Update () {
    45.  
    46.  
    47.         if (DropLangue.value == 0)
    48.  
    49.         {
    50.             for (int i = 0; i < TextFr.Length; i++) {
    51.                 TextFr[i].SetActive(true);
    52.             }
    53.  
    54.             for (int i = 0; i < TextEn.Length; i++)
    55.             {
    56.                 TextEn[i].SetActive(false);
    57.             }
    58.         }
    59.  
    60.  
    61.         if (DropLangue.value == 1)
    62.  
    63.         {
    64.             // Si la traduction en anglais n'est pas disponible ecrire ce sripts
    65.             //FenetreIndisponible.SetActive(true);
    66.             //DropLangue.value = 0;
    67.  
    68.  
    69.             // Si la traduction est disponible écrire ce scripts :
    70.             for (int i = 0; i < TextFr.Length; i++)
    71.             {
    72.                 TextFr[i].SetActive(false);
    73.             }
    74.  
    75.             for (int i = 0; i < TextEn.Length; i++)
    76.             {
    77.                 TextEn[i].SetActive(true);
    78.             }
    79.         }
    80.  
    81.  
    82.     }
    83.  
    84.     public void ButtonIndisponible()
    85.     {
    86.         FenetreIndisponible.SetActive(false);
    87.     }
    88.     public void HandleToggleInputData()
    89.     {
    90.  
    91.         if (OptionToggle.isOn == true)
    92.         {
    93.             OnMusic.SetActive(true);
    94.             On.SetActive(true);
    95.             Off.SetActive(false);
    96.         }
    97.  
    98.         if (OptionToggle.isOn == false)
    99.  
    100.         {
    101.  
    102.             OnMusic.SetActive(false);
    103.             On.SetActive(false);
    104.             Off.SetActive(true);
    105.  
    106.         }
    107.     }
    108.     public void HandleInputData(int val)
    109.     {
    110.         if (val == 0)
    111.         {
    112.             SoundStar.SetActive(true);
    113.             SoundsMuser.SetActive(false);
    114.             SoundsNights.SetActive(false);
    115.             SoundsVirgos.SetActive(false);
    116.             SoundsFollowYourHeart.SetActive(false);
    117.         }
    118.  
    119.         if (val == 1)
    120.         {
    121.             SoundStar.SetActive(false);
    122.             SoundsMuser.SetActive(true);
    123.             SoundsNights.SetActive(false);
    124.             SoundsVirgos.SetActive(false);
    125.             SoundsFollowYourHeart.SetActive(false);
    126.         }
    127.  
    128.         if (val == 2)
    129.         {
    130.             SoundStar.SetActive(false);
    131.             SoundsMuser.SetActive(false);
    132.             SoundsNights.SetActive(true);
    133.             SoundsVirgos.SetActive(false);
    134.             SoundsFollowYourHeart.SetActive(false);
    135.         }
    136.  
    137.         if (val == 3)
    138.         {
    139.             SoundStar.SetActive(false);
    140.             SoundsMuser.SetActive(false);
    141.             SoundsNights.SetActive(false);
    142.             SoundsVirgos.SetActive(true);
    143.             SoundsFollowYourHeart.SetActive(false);
    144.         }
    145.  
    146.         if (val == 4)
    147.         {
    148.             SoundStar.SetActive(false);
    149.             SoundsMuser.SetActive(false);
    150.             SoundsNights.SetActive(false);
    151.             SoundsVirgos.SetActive(false);
    152.             SoundsFollowYourHeart.SetActive(true);
    153.         }
    154.     }
    155.  
    156. }
    157.  
    To give advice to other people in the same situation!
    Check every step of your project with the profiler or directly on the tablet as long as you've created an item in the scene or in a script...
     

    Attached Files:

  22. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,456
    Not necessarily only the ones that the Profiler hints at are problematic. For that language switch via drop-down, you're setting the objects active and inactive every frame. You only need to do that once on start and then when the drop-down value is changed. You can register to the onValueChanged event and only for the setting active if that event is fired. Don't do it in every update. Or remember the last value of the drop-down and only set active if the last value and he current one don't match

    If those spikes in your previous posts only happen on opening the menu, maybe it's not even noticable for the user? Try to find frames that are noticably bad from a users perspective in the profiler and show what's going on in these.
     
  23. Giannigiardinelli

    Giannigiardinelli

    Joined:
    May 8, 2014
    Posts:
    189
    I don't understand everything... For the language change I did this method because I grouped a list of all the text in French and another list for the English text... See the picture...
    The where it beug and lag hugely is when the game this launches at the start of the application ... I'm disgusted not to understand everything and that we do not find the solution ...
     

    Attached Files:

  24. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,456
    This is all you need to do here as a stop-gap measure:
    Code (CSharp):
    1. int currentLanguage = -1;
    2. public void Update () {
    3.         if(DropLangue.value == currentLanguage)
    4.            return;
    5.        currentLanguage = DropLangue.value;
    6.         if (DropLangue.value == 0)
    7.         {
    8.             for (int i = 0; i < TextFr.Length; i++) {
    9.                 TextFr[i].SetActive(true);
    10.             }
    11.  
    12. (int i = 0; i < TextEn.Length; i++)
    13.             {
    14.                 TextEn[i].SetActive(false);
    15.             }
    16.         }
    17.         if (DropLangue.value == 1)
    18.         {
    19.             // Si la traduction en anglais n'est pas disponible ecrire ce sripts
    20.             //FenetreIndisponible.SetActive(true);
    21.             //DropLangue.value = 0;
    22.             // Si la traduction est disponible écrire ce scripts :
    23.             for (int i = 0; i < TextFr.Length; i++)
    24.             {
    25.                 TextFr[i].SetActive(false);
    26.             }
    27.             for (int i = 0; i < TextEn.Length; i++)
    28.             {
    29.                 TextEn[i].SetActive(true);
    30.             }
    31.         }
    32.     }
    I guess it'd be better and would scale to more languages to just set the text in the UI to the text of other languages but that's somewhat more changes.

    Do you mean the time from starting the app to seeing the first scene with the loading text, or the time until you see the loading text or until the second scene is loaded?
     
  25. Giannigiardinelli

    Giannigiardinelli

    Joined:
    May 8, 2014
    Posts:
    189
    Thank you for the code MartinTilo you added the "return" function as I understand it?

    Yes, the first scene loads this quickly. It's when I load my second scene that it lags... Even by removing the coroutine or the ADS script
     
  26. Giannigiardinelli

    Giannigiardinelli

    Joined:
    May 8, 2014
    Posts:
    189
    It takes him almost 1 minute for the game to launch this start the game!

    After the game to throw, it seems to work better when navigating ...
     
  27. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,456
    I don't think your ads script was the problem btw but you'd need to confirm this by comparing the performance with or without it.

    You fixed the Async loading Coroutines as I outlined before? How does the Profiler data for the loading of the second scene look like now. I seem to only find screenshots of the very first load (app startup) and none of the second scene loading.
     
  28. Giannigiardinelli

    Giannigiardinelli

    Joined:
    May 8, 2014
    Posts:
    189
    I totally deleted the first scene because it is useless. The second scene, ie the complete game lags always at the start!
    Made in Unity and then 1 minute of charging and the game starts... No change, if not a small improvement with the navigation of the game, but it's just an impression for me... I haven't tried Unity 2019.3 yet with my game, although I don't think it'll be the solution!
     

    Attached Files:

  29. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,456
    Have you tried to profile the startup of the game? Setting Development Build, Autoconnect Profiler and hitting Build & Run?
    Some loading time is to be expected, some might be optimized and then who knows what else is taking up time there...
     
  30. Giannigiardinelli

    Giannigiardinelli

    Joined:
    May 8, 2014
    Posts:
    189
    I used startup of my game profiler, I test the game with the profiler autoconnect to my tablet.
    For a minute nothing appears on the profiler because the game is charging. After a minute charging here is the screenshot of the profiler and the timeline ...

    I am tired and disappointed to find no solution! one minute loading before display in the menu in my game !! I would like to publish my game and it annoys me not to be able to put it in playStore but my game lags a lot ! i don't can publish one game that lags ! and I would like to look how work ADS with in the "unity Dashboard" !
     

    Attached Files:

  31. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,456
    Could you fold in the JobSystem thread group in timeline and unfold the Loading thread group and show what the loading thread is doing there?

    Also, do you need all your 1357 textures from the very beginning or could you group them into smaller batches, e.g. through AssetBundles or, maybe easier, by having a MonoBevahiour that references the texture and create multiple scenes, each with one GameObject with that script on it which references only to one of these batches each. E.g. if the first set of images that you need for the first quiz is the first scene, you only load that as your startup scene and then, one after the other, Async load the remaining scenes in while the player is dealing with the first scene?

    Also, how big are those textures? Maybe you can save on loading times by changing their size via the import settings (this way you can test this in a non destructive way, just change their max resolution there and and apply) Also make sure that none of them are Read/Write enabled while you're checking their import settings. And try changing their compression settings. Try both turning the compression of and choosing different stronger compressions it.
     
  32. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,456
    Also, turn of MipMap generation if it's on. I suspect you won't gain anything from mipmaps if the textures are always the same distance from the camera.
     
  33. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,456
    Also check this guide.
    Notably the parts about making sure you're setting the import settings for Android and iOS, instead of default and
    Code (CSharp):
    1. On Android when a compression format isn’t natively supported it’ll switch to software decompression which is MUCH slower. Usually for Android you’ll want to stick with ‘ETC2’ texture compression formats, using ‘RGB Compressed ETC2 4 bits’ for opaque textures and ‘RGB + 1-bit Alpha Compressed ETC2 4 bits’ for transparent textures. However if the textures appear glitchy or transparency stops working then use ‘RGBA Compressed ETC2 8 bits’ which results in a slightly higher texture filesize but should fix any issues with the texture.
     
  34. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,456
    If compression helps, there's also a more detailed guide in the manual about the compatibilities and how to make and publish two builds with different compressions for Android devices supporting OpenGL 3 or 2.
     
  35. Giannigiardinelli

    Giannigiardinelli

    Joined:
    May 8, 2014
    Posts:
    189
    Thank you very much @MartinTilo !
    I think we manage to find the problem. Here are the pictures ask.
    That's what I thought. I should have done several scenes as I said at the beginning of the topic.
    As you say my 1357 Textures is not mandatory to be loaded from the beginning of the scene!
    I think that when Gameobject and sub parent its disabling, unity doesn't support them.
    But apparently not! I'm going to have to do what I should have done from the beginning. Creates several scenes for each group of texture lots ask in the player selection...


    I had already tried to reduce the weight of the images. I have put you in a picture of the weight of my textures (all textures make exactly the same weight)
     

    Attached Files:

    Last edited: Apr 19, 2020
  36. Giannigiardinelli

    Giannigiardinelli

    Joined:
    May 8, 2014
    Posts:
    189
    I'm waiting for your answer and what you thought best to do for my game! Thank you again and also for documents !
     
  37. Giannigiardinelli

    Giannigiardinelli

    Joined:
    May 8, 2014
    Posts:
    189
    I didn't understand what I had to do. What are you saying?
     
  38. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,456
    No, if something is in a scene or referenced by something in a scene through an assignment in the editor, it and anything else it references gets loaded into RAM along with the scene, enabled, disabled, active or inactive doesn't matter. Only the shader/material might not be pushed to the GPU before it becomes visible but that's not your problem here.

    I can tell from the TextureImporter screenshot that you already disabled Read/Write enabled (with it enabled memory use would double) and Generate Mip Maps (which would also increase it, because smaller resolution versions would be created and put into the build alongside the full resolution ones.

    So to save more time and memory, do you need transparency on all of them? If not, disable it for the once where you don't need it. (Set alpha source to None and untick alpha is transparency)

    Does your Android device support OpenGL3? If so changing away from ETC2 (if that's the current setting, can't tell from the screenshot) should not help much. If it only supports OpenGL2 it'll fall back to a slow decompression during load so for textures that need alpha you'll want to tick the checkbox for ETC1 and give those textures a packing tag (more on that later). For non transparent textures change the compression to ETC1 (if that's an option the documtation is unlcear if this option was available in 5.6)

    Doyou need them to be 512x512? Do you notice a quality difference if you lower that to e.g. 256x256 or even lower? Lower this as far as you can without quality losses. Each step is a 4x improvement on memory usage and probably loading times.

    POT:
    It seems your textures might not be PowerOfTwo sized. This might affect compression as outlined by the warning box on the bottom of the TextureImporter screenshot. Try setting the POT drop-down to e.g. Nearest or see if you can change their resolution easily to become power of two sized. This might not be as necessary if you set a packing tag though.

    Packing tag:
    Give each texture that belongs to a set (the same sets you would /will use for splitting them into multiple scenes) the same packing tag name. This way they'll all get lumped together into one Atlas Texture. Note that if texture A lands in atlas B, and B contains some textures you don't need just yet when loading texture A, you'll still load all of them in. Atlasses get build based on the tag and their compression and format settings, i.e. alpha and non alpha textures with the same tag would land in 2 different atlases.

    Try all of that and see how far you can bring down the loading times this way. Once you can't Bring it down further, do the splitting into scenes on top of that.
     
  39. Giannigiardinelli

    Giannigiardinelli

    Joined:
    May 8, 2014
    Posts:
    189
    Thank you very much for your time spent using my project. I test the maximum textures 256x256 after if I continue it's slightly pixelated and it's not pretty. I just use this option. Unfortunately this didn't make a huge difference when loading.
    I have win the10 second loading in my game. So I chose to go directly to recreate several scenes. I'll pass the results on to you right here! Whether he's better or not! I hope it works!
    I'll correct my first mistake, but if it didn't solve the problem then I think it's far from making a game on Android with unity3D
     
  40. Giannigiardinelli

    Giannigiardinelli

    Joined:
    May 8, 2014
    Posts:
    189
    Completely outraged about the unity software!


    I've divided several game scenes to add my sprites as you advised me.
    The game starts the first scene takes 15 seconds!

    Then the loads of the scenes with the sprites take more than 30 seconds!
    I am tired!!!!!!

    To look for a solution with this software. A game that goes no further than 2GB! And Unity manages to lags. This software is not made to make Android games!
    Completely disgusted!

    I think the solution is to change software!
     
  41. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,456
    I'm sorry that this didn't resolve the issue for you yet and can understand your frustration. If you're still with to give it a shot, you could try to use the old bitbucket memory profiler to take a snapshot once your first scene is loaded and see if only the textures you assumed would be loaded, are loaded, maybe there are still some stray reference between the prefabs holding the textures?

    On newer Unity versions there'd be the option to use Addressables and the new Memory Profiler but yeah, 5.6 is three years old by now.

    Is the APK or the install size 2GB? Have you compared the install size to other apps and their load times? 2GB ist quite big for a mobile game.
     
  42. Giannigiardinelli

    Giannigiardinelli

    Joined:
    May 8, 2014
    Posts:
    189
    My game is only 190 MB!

    Where the application puts more than 30 seconds, it is on the stage where I installed all the textures ...
    That is, the 1325 images in 256x256!
    So I'm going to have to delete this scene!
    The option to play with all images will be removed.
    I made several options in each scene, there are a number of images to guess, and in one scene, I grouped all the images of the scenes of the game in another scene where there are only the images. When I see that I had to rework, the game to put my textures in several scenes is that it always feels like in my first job! It annoys me a lot...


    I don't know what to think anymore. I have a 3D project on a strategy game. I'm afraid to start this work on Unity. I wonder if I should not directly change programming software.


    Do you have any suggestions to avoid this problem in my next applications which may be much heavier. Because I'm going to use 3D models! I'm afraid the problem itself, but worse. Since my current game only works with images... So imagine a 3D game for an app!?

    Where do I directly change software?
    Thank you in advance and thank you again for your help. You are the only one here since the publication of my ad that gives me advice and helps me not to freak out
     
  43. Giannigiardinelli

    Giannigiardinelli

    Joined:
    May 8, 2014
    Posts:
    189
    I also forgot to ask you. What should I do about the links you sent me?

    and

    As well as now I have the camera that is more than 50% in my unity profiler... I find it all similarly frustrating!
     
    Last edited: Apr 27, 2020
  44. Chris-Trueman

    Chris-Trueman

    Joined:
    Oct 10, 2014
    Posts:
    1,261
    Game development is a job. It requires hard work and dedication to solve all the issues that come with development. It doesn't matter what software or engine you use, it can be very tedious and frustrating to say the least. AAA companies employ 100's if not 1000's of people to make video games so it stands to reason that it takes lots to make a game. One person making a simple game can take months if not years to complete. Terraria, Minecraft, Stardew Valley didn't happen over night, it took years and several other people to do it and they are still being worked on even after being out for years.

    My first game had extremely bad performance. I thought the same thing: "Man Unity isn't very good, what people said was true, the engine sucks!" After realizing I had no idea how to optimize, I did lots of reading and started using the profiler. I got most of the problems resolved, no more stuttering or hicups and game play was consistent. I learned quite a bit from that first project and as I do more I learn more. Learning to play an instrument takes time and practice and so does making video games.

    As for your problem, I think @MartinTilo is doing a great job trying to help. I have no idea, I can only make assumptions. I will tell you to group your textures together into one bigger texture, like with SpriteAtlas. This helped with some of my performance issues I had on my first game. Each texture has some overhead to it, minimizing that overhead is going to decrease loading times. Performance during game play depends on the game and what it is doing, this is where the profiler will help a lot. Seeing how long a method took and how much memory it allocated during that call can show you where you need to optimize.

    One last thing. What functionality is missing in the newer versions of Unity that stops you from upgrading?
     
  45. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,456
    So you split it into an empty scene and one with all the texture? That's not gonna gain you much and not what I suggested.
    I suggested to split the 1325 textures into smaller bundles. E.g. groups of 16 (1024x1024) and reference all 16 (or 8 or 32 or...) of these from one object in a scene with nothing else in. Then you can start the game with the first set or two while loading the remaining scenes (and with them the sprites) Async in the background. As soon as these scenes are then loaded, you can add them to the available ones. (Depending on how your game actually works. I have no idea)

    I also suggested to group them into Atlasses, which should help with the Rendering (what I assume that Camera.Render sample is you're seeing at 50%) as long as sprites that end up on the same atlas tend to show up with others in the same atlas. If they do, they can be batches into one draw call, saving you rendering performance.

    You might want to use the Rendering Profiler Module (chart in the profiler) UI Profiler Module and the Frame debugger to find out how well your UI/ Sprites are being batched.

    I linked you to the memory Profiler because I thought you had split the references to your sprites into multiple scenes, but that somehow that didn't improve their loading times. I thought the Memory Profiler could have helped identify why maybe more sprites are loaded into memory with every scene loaded, the you'd expect. Reading, that you didn't actually split the 1325 textures up but still loading them via one scene in bulk means you can skip that step and instead just split them as suggested. You're not gaining much by having a scene load first that needs all 1325 sprites loaded in bulk by the next scene before being useful to you.
     
  46. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,456
    Game appropriate 3D modules, especially those appropriate for mobile, contain way less data than textures. Sure, you'll also add textures to them but you can get a higher fidelity from the mix of 3dimensionality plus lower res textures than with full on true color images.

    That said, yes there's a bunch of optimization techniques you might need to look into along the way of making that game. There's a lot of tutorials and resources, including on learn.unity3d.com which is currently even offering premium learning content for free during the corona lock down.

    Things to look into before and while making that strategy game:
    • Use a newer Unity version.
    • Make sure you understand about the life cycle of LTS releases and Tech Stream releases, as well as preview packages vs verified
    • Maybe look into the Addressable Assets package, or at least at asset bundles.
    • Profile early, profile often. Spot potential performance problems before you've build systems upon systems that cause them.
    • If you have a system that you expect to be doing a lot of work at some point in the production, try to simulate that expected workload with e.g. random textures, meshes, or whatever data it's supposed to handle.
    • Read and watch a lot of learning material And tutorials.
    I know the frustration. Like @Chris-Trueman I've been at the same point before. Pulling through this means you'll have learned a lot and can continue to learn even more. All this stuff is gonna get easier but you'll find new stuff that's hard at first. That's the nature of the beast really, but also why I like making games. Cause I like to learn new stuff and beat those obstacles.
     
  47. Giannigiardinelli

    Giannigiardinelli

    Joined:
    May 8, 2014
    Posts:
    189
    Thank you for your response!

    To meet @Chris-Trueman

    I agree with what you say, a game does not happen overnight. To answer the question, it's been well over 10 years since I work with Unity 3D today, I discover features, but when I download the version 2019 (I know more exactly where?)! I thought, "God!" What does this thing know... I'm surprised there are no feedbacks on that. I didn't recognize Unity anymore... I felt like I was on another software... Full of errors on my old projects or asset ... The "UI" interface is nowhere to be found!? The interfaces completely change, a misunderstanding after several years of work to know the features and option. The last version I tried, I did not recognize anything, I had to do everything again!


    That's why it's a shame to come up with a change in software. What I don't want, but between the state of operation and the updates. It's hard.


    Thank you, @MartinTilo for your patience.

    Yes, I have listed my Sprites on several stages. As you said, I just put a scene that brings all the images together. It's the one that takes the most time since there are 1325 images.

    I will try to illustrate a diagram of the actions of my game with this image! Hopefully it will help. I have a hard time understanding what you advise me... To make me understand better, here's a diagram. My sprites are on several stages.

    I think the 06 scene that brings together all the images will have to be removed. It is not necessarily useful, but it brings a compilation of all the images of the game ...

    I made a misspelling it's Random script in each scene in the picture publish
    What do you think?


    I agree with you too! I also like to learn new things and overcome these obstacles and create the games I imagine. Hence the reason for my stubbornness to want to solve the problem here!

    Thank you again!
     

    Attached Files:

    Last edited: Apr 29, 2020
  48. Chris-Trueman

    Chris-Trueman

    Joined:
    Oct 10, 2014
    Posts:
    1,261
    Yeah the interface got a face lift. Everything is in the same place though, the icons and buttons look different nothing much else though. The "UI' or uGUI has been moved into a package, which I thought was installed by default which if you upgrade a project it might not. That's one of the problems when upgrading a project to a newer version of Unity, it tends to mess things up and you get tons or errors and warnings, that is why they started LTS versions that remain the same with only bug and stability fixes. The LTS versions are what they recommend to build games with until the next LTS, 5.x didn't have that

    Bringing up my first project again, Google took it down because I mentioned another game in the description which is against guidelines. I went to remove the references to the other game and needed to submit a new APK for it to take effect. Well now they want it to be 64bit and the minimum api changed, which my game was niether. So I attempted to upgrade. I had purchased TextMesh Pro while working on the game to get nice text in the game which is now free(upset me some seeing as I paid for it.) When upgrading the version I was using was out dated and didn't work with the newer version of Unity. I had so many errors, in the end I gave up. The game was a test to see how the whole process worked so it wasn't as big of a deal to have it pulled. One day I will tackle all the errors and put it up again, maybe.
     
  49. Giannigiardinelli

    Giannigiardinelli

    Joined:
    May 8, 2014
    Posts:
    189
    That's the reason, for my obstinacy on the old version of Unity!

    It's as if your signature you've been doing for 15 years, you're changing it another way!
    And if it took you more than 10 years to figure it out. Here's a new signature that will reset everything!
    Have fun doing all the work of your ten years!
    Frankly frustrating!
    You also say you paid for a free Asset today!?
    I find it unacceptable for people who have invested in this Asset!
    The least I can do is get a refund for me! I do not continue in this context, because we are going on another subject! To tell you that the software collects several negative points for me, so far!
     
  50. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,456
    Thanks for the Diagram, that does help understand it quite a good deal better.

    The most curious aspect with that is the difference in loading times between the scenes 04 and 05. It's only a few sprites difference but a 10x difference in loading time. I'd double down on that to see if you can find out what makes 05 that much faster. If you can isolate that, it could help with the other scenes too.

    Also, did you add Sprite Packing Tags to your sprites, e.g. "German_1", "German_2", "French_1" ...

    If you have the RAM budget to spare, to keep all images in memory, you could also you could also start loading scene 02 async and additive in the background as soon as scene 01 has started. Then, once the asnyc loading is done start loading scene 03 async additive, and so forth.

    You can then also either keep the buttons to start into playing with one of the sprites in the scenes disabled until it is loaded, or display a loading bar and start loading that scene, if it isn't already loaded or in progress as the user clicks on it.

    When you do the async additive loading, you only need a Singleton manager script in the first scene, let's call that SpriteCatalogeManager, and all the sounds and UI

    The scenes with the sprites in them only need one script each, lets call that SpriteCatalogePage. SpriteCatalogePage has a reference to all the sprites that should be available with this scene being loaded. (the sprites don't need to be in the scene, just a reference to the asset in the project folder suffices.)

    SpriteCatalogeManager.Awake sets SpriteCatalogeManager.instance = this (a static public field of type SpriteCatalogeManager)

    SpriteCatalogePage.Awake then only needs to call SpriteCatalogeManager.instance.AddPage(this)

    AddPage then can take all the sprites in SpriteCatalogePage and add them to a list of available sprites to be used for random selection. You could have different lists based on some category too.

    The nice thing with this approach is, that you can break the scenes 02-05 down into even smaller sets of sprites, making each scene faster to load, so you'll consistently and quickly be building up that catalog. You won't even need scene 06 anymore, as that will just be the state after all scenes are loaded.

    This way you'll also reduce the time to start into each quiz and go back to the menu (once everything is loaded, it will never be unloaded, which can be slow). This might require a bigger restructure for your code though.