Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

Scroll Rect is TOOO SLOW

Discussion in 'UGUI & TextMesh Pro' started by CircusCharlie, Apr 7, 2016.

  1. CircusCharlie

    CircusCharlie

    Joined:
    Jul 22, 2014
    Posts:
    38
    Hi guys,
    I have a scroll rect inside a canvas with only 15 scrollable items. But it is giving me an fps of 30-40 on my mac and 10-20 on my android device. Any ideas how to fix this ? The UI is pretty simple, I don't know what's wrong. In the previous game that I made with Unity 4.6, I used a lot of scrolls with over 100 items and things were still pretty smooth. I don't know what's the problem this time. Can anyone help me out with this? Thanks.
     
  2. asperatology

    asperatology

    Joined:
    Mar 10, 2015
    Posts:
    981
    You must be constantly updating something. Use Unity Profiler and check what you're doing.
     
  3. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,570
    Try changing from a Mask to a RectMask2D. Should help performance on lower end devices such as Android. Also use profiler ;)
     
  4. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    I just accidentally noticed today (while doing something else) that there is Rect Mask 2D (Added in 5.2?), seems like it automatically disables off-rect children - neat!
     
    radiantboy and karl_jones like this.
  5. CircusCharlie

    CircusCharlie

    Joined:
    Jul 22, 2014
    Posts:
    38
    WOW, this is amazing.. it actually reduced the number of batches from 868 to 111.. great stuff..

    But still the FPS drop remains the same. On my mac, when I start scrolling the items, the FPS goes from 60 to 40-45 .. and obviously the performance is pretty bad on my android device. Kindly help me out with this. This is what my scroll looks like

    @Everyone thank you for your replies, really appreciate it.
     

    Attached Files:

  6. CircusCharlie

    CircusCharlie

    Joined:
    Jul 22, 2014
    Posts:
    38
    I would also like to mention that the sprite packer isn't helping either. All the images that you see in the scroll are packed using sprite packer, but it just doesn't effect the batches count at all. 111 batches for a few scrollable items on the screen are still too much :(
     
  7. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,570
    Open the frame grabber window and take a sample. Are they being batched? Are you using nested canvases?
     
  8. CircusCharlie

    CircusCharlie

    Joined:
    Jul 22, 2014
    Posts:
    38
    Well no, nothing is being batched. Saved by batching is zero. And no, I am not using multiple canvases, everything that you see is under one canvas root. Thanks again for replying :) Screen Shot 2016-04-16 at 3.58.04 PM.png
     
  9. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    Can you post an image showing the hierarchy of one of these elements in this scroll list so we can see how they are setup and what components are used? I would like to know how many UI.Text you are using, Image, etc... maybe vertical layout groups, content size fitters, etc.

    Assuming you are using UI.Text and sprites, I count maybe 4 UI.Text objects and 3 sprites per element.

    I would like to sort of recreate one of those to check performance and see what potential optimizations might be possible.
     
  10. CircusCharlie

    CircusCharlie

    Joined:
    Jul 22, 2014
    Posts:
    38
    Sure, here it is :- Screen Shot 2016-04-16 at 4.07.10 PM.png Screen Shot 2016-04-16 at 4.07.25 PM.png
     
  11. CircusCharlie

    CircusCharlie

    Joined:
    Jul 22, 2014
    Posts:
    38
    I am using Unity 5.3.3p3 personal. I downloaded this patch p3 because I read it somewhere that this patch was launched to solve the canvas issues with performance, but It didn't effect the performance at all.
     
  12. CircusCharlie

    CircusCharlie

    Joined:
    Jul 22, 2014
    Posts:
    38
    This is the hierarchy Screen Shot 2016-04-16 at 4.13.09 PM.png of one of the contents inside the scroll
     
  13. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    Any chance you can show each of those so I can see what Layout Components they might be using or maybe you can provide a scene / package that mirrors this without your specific graphics and all just so I don't have to guess when trying to rebuild that hierarchy?

    Ie. I want to be able to reproduce the exact setup with whatever components (including layout components since they can impact all of this).
     
  14. CircusCharlie

    CircusCharlie

    Joined:
    Jul 22, 2014
    Posts:
    38
    Sorry, I won't be able to send a scene or a package as it would be against my employer's policy, but Ive attached the inspector screenshots of my Canvas, Content (parent of all items inside the scroll view) and one of the items of the scroll. You can see what layout components have been attached to each of those. Screen Shot 2016-04-16 at 4.19.04 PM.png Screen Shot 2016-04-16 at 4.19.21 PM.png Screen Shot 2016-04-16 at 4.20.09 PM.png
     
  15. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,570
    Are you able to share the project/scene?
    It may also be worth trying the latest patch of 5.3. That will include all previous fixes such as the 5.3.3p3 ones.
     
  16. CircusCharlie

    CircusCharlie

    Joined:
    Jul 22, 2014
    Posts:
    38
    Sorry, I will not be able to share the project/scene as it will be against the policy of my employer. And I did try the latest patch of 5.3 as well. But it didn't solve the problem either.
     
  17. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    So you don't have any layout components on the child like Coin Image or Level Text, etc... All of those in that hierarchy are driven by the layout components on the parents right?

    The coin image has a name text and does it also have an image with the sprite?

    I'll try to recreate a similar scene to see what results I get and see what potential tweaks I think would make sense to get you better performance.

    P.S. Can you show me the inspector of one of the text objects? I want to see if you have an Outline or Shadow script on there. If you do, I presume you have one on all the others and you seem to also be using that on your sprites as well.
     
  18. CircusCharlie

    CircusCharlie

    Joined:
    Jul 22, 2014
    Posts:
    38
    Yes, there are no layout components on any of the child components like Coin, image, level text etc. They are all driven by their parents.

    Yes the coin is a sprite and it's child is a text.

    Every text that you see has outline on it

    Thanks a lot for your efforts I really appreciate your help. Screen Shot 2016-04-16 at 4.35.55 PM.png
     
  19. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    Thanks for sharing all the information.

    Since it is 4:00 AM for me, I am going to go sleep but I will recreate a similar configuration tomorrow and share my findings with you.

    P.S. I already know that I can get you better performance on all your text objects and reduce the geometry count by a good amount (4X) which should make an impact. I also believe we can also get that on your sprites.
     
  20. CircusCharlie

    CircusCharlie

    Joined:
    Jul 22, 2014
    Posts:
    38
    Thanks a lot Stephan.
     
  21. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    See my P.S. Edit :)
     
  22. CircusCharlie

    CircusCharlie

    Joined:
    Jul 22, 2014
    Posts:
    38
  23. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    I have attached a Repro Scene for you to look at to make sure I didn't miss anything in my attempts to reproduce your setup. Please make any changes necessary to mirror your configuration / scene to make sure I am able to reproduce the performance issue you are having.

    upload_2016-4-16_19-42-17.png

    Once you confirm you are also experiencing the same performance issues with this scene or whichever revised version you provide me, I'll get to work on looking for optimizations.

    P.S. I forgot to swap the UI.Mask for a 2D RectMask.
     

    Attached Files:

    Last edited: Apr 17, 2016
    rakkarage likes this.
  24. CircusCharlie

    CircusCharlie

    Joined:
    Jul 22, 2014
    Posts:
    38
    Stephan, this is what I have been doing, thanks a lot for your efforts. All though this is a little better optimised than my version but still it will give me grief on androids. Right now, on the mac it gives me the fps of 60 and when I scroll, it can go down to 51-52, while mine ranged from 60 to 40.

    So, I set the target framerate to 120. Now, on my mac the fps is around 65-68. But if I deactivate the scroll view parent then the scene has nothing but a canvas and a text that shows the fps. The fps at that point is between120 to 160. And when I activate the scroll view parent, the fps again drops to 65.

    I don't understand why a simple scroll view is effecting the performance so much. some of my screen designs require 2-3 scroll views on the same screen visible at the same time. I have done this several time with NGUI without any issues. I even did this with Unity's UI in 4.6. That game had 2 really long scrolls on the same screen and I didn't even use object pooling. It still ran perfectly fine on an Iphone4s and androids.

    I fail to understand why is the performance so poor now.
     
  25. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    When I run the scene I supplied and enable or disable the Scroll Rect on the Scroll View object, I see no change in performance (FPS) and when I scroll up and down, no impact either.

    Can you try the same thing again with the scene I provided to see if you get the same behavior or if you still get a drop in FPS?

    P.S. This scene isn't (really) optimized by the way. On a Galaxy Tab A, it runs at 15 fps but I do have an optimized version running at 42. The same scene on an iPad 2 (non retina) runs at 19 fps whereas the optimized one runs at 60 fps. Having said that, before taking a look at how I got those improvements, I want to reproduce the behavior you are experiencing on your end to make sure I am not overlooking something else.
     
    Last edited: Apr 17, 2016
  26. CircusCharlie

    CircusCharlie

    Joined:
    Jul 22, 2014
    Posts:
    38
    The stats that I provided in my previous comment came out of the scene that you had provided.

    I set the target framerate to 120. Now, on my mac the fps is around 65-68. But if I deactivate the scroll view parent then the scene has nothing but a canvas and a text that shows the fps. The fps at that point is between120 to 160. And when I activate the scroll view parent, the fps again drops to 65.
     
  27. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    If I understand correctly, you are going from no text on screen (just a rectangle with the FPS) to several elements with text and sprites displayed? If that is the case, the frame drop isn't related to the ScrollRect but just CPU and GPU overhead in displaying all those items on screen. Correct?
     
  28. CircusCharlie

    CircusCharlie

    Joined:
    Jul 22, 2014
    Posts:
    38
    yes, correct
     
  29. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    If you do the same thing without a ScrollRect, you will notices the performance impact is coming from displaying all those items.

    In the example I provided, I am still using UI.Text with Unity's Outline FX (script). The Outline FX script is greatly impacting your performance and UI.Text just a little bit but nowhere near what the Outline FX script does.

    I created the same setup using TextMesh Pro (my product) which besides offering a ton of additional functionality over UI.Text, uses a different way to add Outline, Shadows and a lot more which have almost zero performance overhead unlike the Outline and Shadow script that Unity provides. Here is an example of the same setup using TextMesh Pro

    upload_2016-4-18_12-43-5.png

    The performance of this visually identical result is 3X faster than the other one using UI.Text + Outline script. The outline on the text is done using material properties which I explained along with performance stuff in the following thread.

    The 3.45 B and the sprite are also the same object since TextMes Pro supports inline graphics so the text for that object is
    3.45B <sprite="sprite asset" name="coin">. Although I kept Player Name and Level as two objects they could also be combined but it would be cleaner to keep them separate as you need to change that in code I presume.

    The 24 on the stars, is using the same font as the rest but with a different material preset (which allows you to create an unlimited number of visual styles) this is also covered in the other thread I linked.

    So, on your end, disable all the Outline FX and check performance again and you will be surprised. Then if you need better text handling and functionality and want those Outlines and even Shadows back at not performance cost, take a closer look at TextMesh Pro.
     
    DadNapper likes this.
  30. zero_null

    zero_null

    Joined:
    Mar 11, 2014
    Posts:
    159
    Hey Guys!
    I have pretty bad Performance with ScrollRect !
    Any remedies ?
    Please help.
     
  31. xucian

    xucian

    Joined:
    Mar 7, 2016
    Posts:
    860
    maybe this helps
     
    Shahab-Mirza likes this.
  32. Wahooney

    Wahooney

    Joined:
    Mar 8, 2010
    Posts:
    281
    Hi,
    I'm also having a performance issue with ScrollRect (in 5.5.2f1).

    After deep profiling (216ms) I found that a huge slice of the performance goes to:
    • VertexHelper.Clear()
    • 53ms - Image.GenerateSimpleSprite()
    • 45ms - Image.GenerateSlicedSprite()
    • 16ms - Text.OnPopulateMesh()
    • VertexHelper.FillMesh() is a bit greedy too @14ms.
    So out of a 216ms total, 114ms is spent on VertexHelper.Clear(), which is nuts for what should be a bit of data wrangling.

    In this example am drawing 13 items in the ScrollRect with ~25 graphics elements in each, so it's not exactly a light ui, but it's not insanity either. When scrolling this list in a non-profiling build, it slows to 15FPS from 60.

    It would be nice if ScrollRect just transformed pre-built ui around rather than rebuilt EVERYTHING.

    Any advice?

    Edit: PS I can't upgrade to 5.6 yet because of the ScrollRect NaN bug.
     
  33. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,570
    The fix for the ScrollRect NaN bug is in 5.6.0p3 which is available now.
     
  34. Wahooney

    Wahooney

    Joined:
    Mar 8, 2010
    Posts:
    281
    I know ;) But our policy is to work on non-patch releases for live projects
     
  35. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,200
    That's a weird policy, if you don't use patch builds, you'll get stuck waiting for the next full release.

    The NaN bug we fixed by changing our main camera size to larger. Since our canvases are screen space - camera, this helped prevent the bug for us on 5.6.0f3.
     
  36. Ali_V_Quest

    Ali_V_Quest

    Joined:
    Aug 2, 2015
    Posts:
    138
    Thanks
     
  37. Chefty

    Chefty

    Joined:
    Jun 17, 2015
    Posts:
    43
    Greetings guys,

    I'm digging out this topic because it perfectly match my current situation.
    I'm now on unity 2017.3.1f1 and still, ScrollRect UI badly impact performances of my project.
    I have tried the @Stephan-B scene and from the unity game windows I notice a ~40-50fps drop when I scroll the content.

    I haven't found any working solution out there sor far.
    Does anyone know if there is any way to use Unity's built-in ScrollRect without having framerate drops ? :confused:
    If not, any alternative without buying assets ?

    Cheers,
     
  38. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,200
    Take a look here https://bitbucket.org/UnityUIExtens...ontrols#markdown-header-additional_components

    Or something like https://unitylist.com/p/dwd/Unity-Dynamic-Scroll-Rect

    There are tons of free sources that use object pooling instead of just tossing everything into a scroll rect which is usually the source of issues.

    Otherwise, use the profiler to figure out what may be slowing things down when you scroll, that might be your best bet if another solution doesn't present itself.
     
    miticatechnology and Chefty like this.
  39. Chefty

    Chefty

    Joined:
    Jun 17, 2015
    Posts:
    43
    @Brathnann thanks a lot, the UnityUIExtensions repository is really useful !
    Still I'm having framerate drops when I perform a scroll (with HSS for example).
    Although I'm starting to think the UI mask is involved.
    Cheers,
     
  40. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,200
    If it's a mask issue, there is a 2d rect mask that is suppose to be better. I think they made some improvements to it in 2018.2 I think I saw in the patch notes.
     
  41. Chefty

    Chefty

    Joined:
    Jun 17, 2015
    Posts:
    43
    Yes I already tried the 2D rect mask, indeed it's improving the performances.
    However I'm using the Curved UI asset and it doesn't seems to be compatible. I got some display glitches on the sides.
     
  42. realmaster42

    realmaster42

    Joined:
    Jun 1, 2017
    Posts:
    2
    Late two years, but thank you so much for this.

    Why isn't this the default component for ScrollView? ;)
     
  43. Zoltantan

    Zoltantan

    Joined:
    Dec 20, 2012
    Posts:
    1
    Hello Guys!

    I also bumped into something like this one but I managed to solve it in the following way. ( I have 3 TextMeshPro dropdowns with 256 items each )

    Code (CSharp):
    1. public class MyClass: MonoBehaviour
    2. {  
    3.     private List<TMPro.TMP_Dropdown.OptionData> options = new List<TMPro.TMP_Dropdown.OptionData>();
    4.  
    5.     void Start()
    6.     {
    7.      
    8.         TMPro.TMP_Dropdown dropDown = gameObject.GetComponent<TMPro.TMP_Dropdown>();
    9.         for(int i = 0 ; i++ ; i < 256 ) {
    10.             //craft and add option item here
    11.         }
    12.         dropDown.AddOptions(options);
    13.     }
    14. }
    Before this I had my list initialized in Start and it turned out that was the issue. Note: I have 1300 fps currently in the scene, opening a dropdown drops it to ~30 but almost immediately recovers.

    EDIT: Drop is related to a script that scrolls automatically to the previous selected item. So if first item is selected it drops to ~70 fps, when last is selected then ~10
     
    Last edited: Jul 25, 2018
  44. asperatology

    asperatology

    Joined:
    Mar 10, 2015
    Posts:
    981
    Indeed, it should be expected to work fine, because you're using TextMeshPro dropdowns.

    Just for context, this entire thread's discussion is all about doing dropdowns with massive amounts of items during the times when TextMeshPro isn't even integrated, let alone bought by Unity, into the editor.
     
  45. unity_1cewWbGw8rRVxw

    unity_1cewWbGw8rRVxw

    Joined:
    Jun 6, 2018
    Posts:
    9
    Thanks
     
  46. TMSAL

    TMSAL

    Joined:
    Oct 19, 2015
    Posts:
    1
    Hi everyone, I had the same problem, discovered that by setting the quality settings to medium instead of very low actually make it better.
    To change the project quality settings go to edit=>projectsettings=>quality=> click on the default black arrow below android platform and select medium.
     
  47. miticatechnology

    miticatechnology

    Joined:
    Oct 30, 2014
    Posts:
    14
    Hi! how are you?

    I solved it with UI_ScrollRectOcclusion script from first link,

    Thank you @Brathnann
     
  48. SomeVVhIteGuy

    SomeVVhIteGuy

    Joined:
    Mar 31, 2018
    Posts:
    162
    The original solution of "Mask to a RectMask2D" (removing the Mask component of the "Viewport" of the Scrollview, and replacing it was a RectMask2D) definitely had the biggest impact on performance for me.

    additionally I:

    Divided my UI elements into different canvases(Static, and overlays that are never up at the same time), to keep everything on canvas from updating with each change of input. By default, as far as I understand it, every child of an object is check and updated whenever there is relevant input. so if you are using a scroll feature, it updates every single element on your canvas as a part of update(). Another large impact of performance for me.

    Checked that all objects that are never supposed to be interacted with (simple images, non-TM pro Text) are not raycasted. (simple check box in inspector) Do NOT do this for your "Viewport" on a Scrollview if you have space between the content objects, as it will make your content not work correctly if a drag starts from that space. Minor Performance boost.

    My UI is purely an overlay, and does not require use of a specific camera. but that can be very taxing if using Camera.main.

    all these solutions together made my 100-300 item scrollviews much more smooth at actual runtime on android.
     
    Glitchparis likes this.
  49. justtime

    justtime

    Joined:
    Oct 6, 2013
    Posts:
    431
    When i switched from Mask to RectMask2d i've got 2.5x slower performance
     
  50. outthinking01

    outthinking01

    Joined:
    Sep 22, 2014
    Posts:
    9
    This worked! thanks a lot.