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
    Thanks to you @MartinTilo!
    You are precious in this forum of unity! Thank you again...

    I'm a little overwhelmed in what you're saying and I don't understand everything.
    The diagram I shared with you is only an example summary of my game to better understand. It is not 100% accurate!!




    The change of scenes that take time, its due to the number of sprites to load ... I have no doubt!
    How do you want to make an early loading on each stage? Is that beyond my competence with Unity?



    Yes, I understand better. You mean I should include them in my scene via my "Project" folders.
    This would mean redoing a whole script for 1) insanciated in the scene, and 2) after insanciating my images to list them in a library to choose a random image via loading the number of images ...
    Is that what you're telling me?
    Which would put my game back on suspension
     
  2. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,457
    According to that diagram, loading scene 04 with 175 sprites takes 10sec, loading scene 05 with 150 sprites takes 1sec, so it's 10 times as fast, while only being 25 sprites less.
    If those timings are somewhat accurate, check what the difference between these scenes is.

    And yes I think you got what I meant. It's just a suggestion on how to change things for shorter loading times until the user can play something.

    Did you add the Packing Tags yet?
     
  3. Giannigiardinelli

    Giannigiardinelli

    Joined:
    May 8, 2014
    Posts:
    189
    I just wanted to do an example diagram to better understand. Now I'll tell you how many "Sprites" actually contain in my scenes...

    I'll see how I can possibly do the work you're suggesting, but it might not be that easy to do. Let's hope it works. But I'd have to write a script in your idea.


    Tell you about the "Packing Tags" of my "Sprites"?
    No, there's nothing written about it. I'm discovering this mode. What do you want to tell me about that?
     
  4. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,457
    You should set that field in your sprite importers to some string. All sprites with the same string will be baked into an atlas. If one sprite in that atlas is loaded into memory, all sprites in that atlas are loaded into memory, so the string should be the same for each set, e.g. English_01, German_01, ... The same grouping as for the scenes, to avoid that one scene accidentally loads in the sprites from another scene already.

    This might improve loading times, because loading will happen in less fragmentated blocks, but mainly, it should reduce rendering time, since all sprites in the same atlas can be rendered in one batch.

    I'd try that first before changing too much else in the scripts, just to see how much this would improve things already.
     
  5. Giannigiardinelli

    Giannigiardinelli

    Joined:
    May 8, 2014
    Posts:
    189
    When I collected the sprites, I could see something in my opinion that will change the game on the loads of my scenes. That you really have to re-analysis everything to find solution. Another mistake on my part!! I had forgotten that I had made a operation, which in my opinion is a bit barbaric. I think there is surely a much smarter solution to achieve... You'll understand:

    • Scene 01 > Loading Game Menu > 20sec, for me my opinion it takes a lot of time.
    • Scene 02 > Playing > with : 440 Sprites + 1 Sprite icon flag ! = 10 Sec of loading !!!!!
    • Scene 03 > Playing > with : 113 Sprites + 1 Sprite icon flag ! = 05 Sec
    • Scene 04 > Playing > with : 249 Sprites + 1 Sprite icon flag ! = 10 Sec !!!!!
    • Scene 05 > Playing > with : 40 Sprites + 1 Sprite icon flag ! = 02 Sec
    • Scene 06 > Playing > with : 57 Sprites + 1 Sprite icon flag ! = 03 Sec
    • Scene 07 > Playing > with : 925 Sprites + 1 Sprite icon flag ! = 25 Sec !!!!!
    • Scene 08 > Playing > with : 24 Sprites + 1 Sprite icon flag ! = 02 Sec
    • Scene 09 > Playing > with : 364 Sprites + 1 Sprite icon flag ! = 10 Sec !!!!!
    • Scene 10 > Playing > with : 1325 Sprites + 1325 Sprite icon flag ! = 35 Sec !!!!!
    Thank you again, I think I have found the problem that will prevent me from inseating all the images thanks to you.
    As I said earlier, that's what I think I found.

    I have a scene, with 1325 sprites and 1325 flag icons correspond to the square of the random image, which points you to the image - the name of the image - the flag of the country of the image. Which finally makes 2650 sprites to load... There are 10 different countries in the game, maybe there is a way to avoid getting unwise work and make it work with my 10 flags and match each image with the right sprite. This would avoid loading the 1325 icons!

    It's pathetic of me... your idea and much better! I didn't think to instancier the images...

    Follow-up, my two mistakes. That is to say do the whole game in one scene... And add the flag icon sprites corresponding to the list of images...
     
    Last edited: May 1, 2020
  6. Giannigiardinelli

    Giannigiardinelli

    Joined:
    May 8, 2014
    Posts:
    189
    I'm having a hard time understanding. In fact, you mean naming the images that match my scenes?

    That is, in scene 01 there are 50 images I have to write in "Packing Tages" the same reference to the 50 images? Example "English"

    And

    in scene 02 which has 250 images I also write to each in "Packing Tages" 250 times corresponding to the images? Exempe "French"

    What would save time with this option ? Is that what you're saying?
     
  7. Giannigiardinelli

    Giannigiardinelli

    Joined:
    May 8, 2014
    Posts:
    189
    I tested using only one flag, it's always the same finally we win maybe 5 seconds good I expect your point of view and on the board "Packing Tages"
     
  8. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,457
    Well, no not renaming the textures themselves but just setting the Packing Tags of them to the same Tag name. I think you understood that much though, just to be sure.

    Yes

    Maybe loading times, definitely rendering times.
     
  9. Giannigiardinelli

    Giannigiardinelli

    Joined:
    May 8, 2014
    Posts:
    189
    Hello @MartinTilo

    I will finally my new game on Google Play and enjoy sharing it with you! Even if the problem is not completely solved. Loading certain scenes or launching the game uses more than 10 seconds. What concerns me, stay a little long!
    For Information Google Play, want an application that does not exceed 150MB maximum! My game was 200MB. So I was able to remove what is not usable in the folders and reduce the qualities, some files. Without it being visible on the devices!

    I had one last question before confirming the application! This is Unity3d's famous ADS question. For several months of work, we must make our time come true for a little money!

    I've learned about a lot of articles about ADS and there's so much information that it's hard to be sure to be compliant with what's being said. That is why I wanted to ask you a question about that. Here's the code I use for advertising. For the record, I put into service on "On" for monetization and then tested, if the advertising works well in the game! My question, will this script shown here work to be paid for by Unity?

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5. using UnityEngine.Monetization;
    6. public class ADSManagers : MonoBehaviour {
    7.  
    8.     private int rewardCount = 0;
    9.  
    10.     private string gameId = "1234567";
    11.  
    12.     private string placementId_video = "video";
    13.     private string placementId_rewardedVideo = "rewardedVideo";
    14.     private string banner_ad = "bannerAd";
    15.  
    16.     public bool ActivePub = false;
    17.  
    18.     void Start () {
    19.  
    20.         if (Application.platform == RuntimePlatform.Android)
    21.             gameId = "1234567";
    22.  
    23.         Monetization.Initialize(gameId, true);
    24.        
    25.     }
    26.  
    27.     public void ShowAd()
    28.     {
    29.         //StartCoroutine(WaitForAd(true));
    30.         ActivePub = true;
    31.  
    32.         if (Monetization.IsReady(placementId_video))
    33.         {
    34.             ShowAdPlacementContent ad = null;
    35.             ad = Monetization.GetPlacementContent(placementId_video) as ShowAdPlacementContent;
    36.  
    37.             if (ad != null)
    38.             {
    39.                 ad.Show();
    40.             }
    41.         }
    42.     }
    43.  
    44.  
    45.     void Update ()
    46.     {
    47.  
    48.     }
    49. }
    50.  
    Thank you for your help and confirmation!
    I would make a conclusion for my topical use here. For the people, who will be concerned about the same problem as me!

    I thank, very much, Martin Tilo who really took the time to help me and try to find a solution. Even if the problem is not completely solved. Would you be your name or something, would you be happy, if you like?
    Thanks in advance, I'm waiting for your answer on the ADS script question and then I'll publish a conclusion as well as my game!
     
  10. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,457
    Hi again and good to hear you got it to a good spot, or at least good enough for now.

    It's been a while since I worked with the ads API but checking with the documentation, that looks to a be corrected usage of it to me.

    Good luck with the game launch :)
     
  11. Giannigiardinelli

    Giannigiardinelli

    Joined:
    May 8, 2014
    Posts:
    189
    Thanks for the documentation. You say you don't use ADS. What service do you use? Is it possible to use another advertising service?
     
  12. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,457
    I'm not making games for profit these days, as I focus my work on the Unity Profiler toolstack instead ;)

    But yeah, there are other ads services and plugin sdks for Unity but I'm not really in the know about these.
     
  13. Giannigiardinelli

    Giannigiardinelli

    Joined:
    May 8, 2014
    Posts:
    189
    Okay thank you @MartinTilo
    You confirm with the code so on that the service will work to pay me for advertising view?
    I'll keep you informed when the game is released. I'd come and put the link here. And a conclusion for those who wish.
     
    MartinTilo likes this.
  14. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,457
    as long as you're replacing
    gameId = "1234567";
    with you're actual cloud project id, it should work. But there should also be ways for you to test this. As i said, it's not my area of expertise so this is just me looking at the documentation and comparing what's there with what you have here.
     
  15. Giannigiardinelli

    Giannigiardinelli

    Joined:
    May 8, 2014
    Posts:
    189
    Yes, of course I have to put my cloud project ID!
    Thank you again @MartinTilo
    I'll send you the link of the game you'll tell me what you think!
     
    MartinTilo likes this.
  16. Giannigiardinelli

    Giannigiardinelli

    Joined:
    May 8, 2014
    Posts:
    189
    I'm going to publish my game with the Unity 5.6.4 version as stipulated here!
    I reduced my file to 100MB to be allowed to publish it while the game was making it 200MB. And with my luck and my good star. I'm in trouble again!

    I'm going to have to update Unity 2019.3.14 to install what Google Play wants! The 32-bit and 64-bit! I think this is due to the update to Google Play and their restriction! So I'll see if I'm going to get away with the new Unity update. I hope to return to the CANVAS UI function. Hoping that my project does not get a ton of error. Or worse yet to redo the whole project!

    This is the fighter's journey to publish a game for Android with Unity !!!!! And with little information about it!

    @MartinTilo If you have a solution to this problem for version 5.6.4 I'm listening to you. For now I keep you informed if with the new version of Unity I manage to publish the game!

    Thank you in advance!
    Here are the links that informs my current problem and come up with a walking solution!

     
  17. Giannigiardinelli

    Giannigiardinelli

    Joined:
    May 8, 2014
    Posts:
    189
    It's good to work!
    Unit software update
    To have multiple unit version. I had to import the package to extract it on the Unit up to date and to succeed
    The game had some error to rectify at ads level
    The well-exporting game on GooglePlay
    Attending publication!

    I'll keep you an informant
     
  18. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,457
    Oh nice. I was gonna say that it looks like it might've worked to upgrade to 2017.4 or 2018.4 too and that up generally it's advisable to upgrade (with backups) in stages, going through these mayor versions. But nice to hear it worked for you to jump straight ahead.

    Have you checked the performance on 2019.3? Would be interesting to know how that might have been affected.

    (Side note on Profiling the performance here: 19.3.14f1 has a bug when trying to take a Menory snapshot where it might hang forever but once 2019.3.15f1 is out you could use that version together with the Memory Profiler package to get some better info on your memory usage. The bug doesn't affect release builds obviously so it's still safe to release on that version)
     
  19. Giannigiardinelli

    Giannigiardinelli

    Joined:
    May 8, 2014
    Posts:
    189
    Thank you

    Yes, I did a "UnityPackage" of my game. Importing into the new Unity to properly reinstall all. The options and some problem on "ADS" because I had imported the ad asset. And in the 2019 version of Unity3d it is integrated. Hence I think of mistakes.

    For the version I installed of Unity3d. It looks better than the one I downloaded. I'm glad it works! Indeed it would be interesting to look at the profiler's performance. But the game has not improved compared to the Unity5.6.4 version with that of 2019. I watched the "profiler" and it still displays the same data.

    I made you a screenshot:

    • Profiler : Start scene loading > scene Menu (10 second)
    • Profiler02 : Starting the longest time scene of player select and (10 second)
    info : For information: I remove my scene that loads the 1325 images and is not performing the method of importing images from my folders into the scene randomly...

    In the "Build Settings" window, there are many more options. I've selected:

    • Build App Bundle (For my game Android)
    • Development Build
    • Autoconnect Profiler
    • Deep Profiling Support


    Tell me if there are new options for better accuracy in the 2019 version of Unity to improve performance?


    I would publish the link to my game when it is admitted to publication. Let's hope I don't run into a new problem!
    Thank you again.
     
    MartinTilo likes this.
  20. Giannigiardinelli

    Giannigiardinelli

    Joined:
    May 8, 2014
    Posts:
    189
    Screenshot Profiler
     

    Attached Files:

  21. Giannigiardinelli

    Giannigiardinelli

    Joined:
    May 8, 2014
    Posts:
    189
  22. cyclSunity

    cyclSunity

    Joined:
    Jun 10, 2020
    Posts:
    123
    Is your droid device have low storage?
     
  23. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,457
    Thanks and congratulations on your first released game :)

    I just gave it a test run. Some feedback:
    • I don't understand how to unlock new categories or nationalities, especially since there seems to be no win state?
    • There's some issue with the resolution on my phone, where the UI has artefacts on the top and bottom. See attached screenshot. You could use the resolutions drop down in the game view or the Device Simulator to test your game at different resolutions in the editor.
    • Some part of the UI aren't translated to English, like the Yes and No buttons on "do you really want to go back to the main menu" dialog.
    • The sound options don't appear to be saved
    • You are displaying incentiviced Ads but there is no actually incentive, no gain from watching them to the end. This is probably not ideal for monetization as it means you can abort the ads immediately.
    • Why is there an ad after closing the options menu?
    Other than that, this could be an interesting way for building a better face-to-name recognition Memory for me, which is something I'm seriously lacking when it comes to celebrities. I just don't know how to unlock categories other than French celebrities, which I seem to recognize even less of :D

    Anyways, making your first game is tough, let alone publishing it, so once again, congrats on shipping your game :)
    May there be many more to follow!
     

    Attached Files:

  24. AlexiFullerman

    AlexiFullerman

    Joined:
    May 1, 2020
    Posts:
    6
    >> It's really sad that in a mobile world Unity still lags(pun) on optimization, basically you need to split up and deactivate everything not in the camera few circa 1985.
     
  25. AlexiFullerman

    AlexiFullerman

    Joined:
    May 1, 2020
    Posts:
    6
    >>3D is tough, you will need to constantly deactivate EVERY game object not in camera view, a 500X500 terrain will need to be split into 20 pieces to keep the vert count down, every texture is 512 or less, you might get 25 fps on Galaxy 5+ phone. Forget google glass with 3D, lag city.
     
  26. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,457
    @AlexiFullerman the optimization topic in this thread is done. The game has been optimized and shipped.

    Your ranting about performance here is not relevant to the project at hand and hugely off-topic. His game has 0 terrains an 0 3D elements. His next game might but the concern here was that the load times might be as high as it was here, not the real time 3D performance.

    Besides that any mesh, that doesn't span huge areas (like terrains) and therefore never really leaves the cameras view, is getting culled by view frustrum culling so your advice is wrong on top.

    It sounds like you're projecting issues you've encountered in your own projects here and I'm sorry to hear of your level of frustration with Unity. If you want any advice on how to solve your issues and maybe in a better way, please open a new thread (and if terrain related, in the World building subforum) though.
     
    Last edited: Jul 12, 2020
  27. AlexiFullerman

    AlexiFullerman

    Joined:
    May 1, 2020
    Posts:
    6
    Hold on there buddy, talking about splitting up terrain to increase performance on FPS is not a "rant," you need to slow down and soak up this thread. Not all of our customers go out and buy new phones that can handle high speed graphics. We need to dig down deep and strip out everything so they can enjoy the decent graphics on just about any platform, that's what I'm pointing out. It's not a "rant" to rip out all the stops to give the customer, who download the demo game for free, the best user experience possible, is it? We are in it for the long haul.

    So now who is your customer? Is it the the person who buys the pro pack/asset store or the guy with 5 year old phone enjoying a game and putting up with our adverts to get to the next level? Gotta tell ya, if the end user is not happy we are all sunk, and yeah I have worked on a few titles, and dealing with slow FPS is always on the top of the list, most programmers will agree, at least the ones who push out prroduct.
     
  28. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,457
    My apologies, I didn't mean to discount the struggle behind getting games, especially graphically ambitious ones, shipped on phones that aren't the recent flagship games. I've had to make one such 3D game run on an iPhone 4 & 4s while the 6s was already out and know the struggle. We didn't use terrain but a custom solution for ground tile texture blending that needed quite some trickery, that felt similar to some of the tricks used in old 16bit games to compress more info into the textures. Fun in way, and entirely not fun in another.

    That struggle is there and real. And yes, if it doesn't run on the end users device then what's the point.

    I would just advice you to raise your valid feedback regarding the terrain system in a separate thread in a fitting sub-forum to ensure that the right people get to see it and can respond to that feedback on its own merits.
     
  29. VEOdev

    VEOdev

    Joined:
    May 3, 2021
    Posts:
    1
    Watch this video hope it fix your problem