Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by sarahnorthway · Mar 09, 2018 at 09:29 PM · 2dguiscrolling

Why is my Scrollrect content jittering?

I've got a 2d UI in Screen Space - Camera containing: ScrollRect > Viewport > ContentSizeFitter > Text

The text is short so it fits without triggering a scroll bar. Everything SHOULD be at Y = 0. Instead, the ContentSizeFitter's Y is changing to values between -0.003 ~ 0.003 at every frame. It makes the text jitter up and down.

Same issue on a different ScrollRect containing a long grid of images, even after scrolling down.

I noticed this after upgrading to 2017.3.1f1 but not sure if this is a Unity bug or mine. My camera follows a NavMeshAgent around a 3D scene, but movement stops when the menu is showing.

Any ideas?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
6
Best Answer

Answer by sarahnorthway · May 17, 2018 at 09:55 PM

I'm guessing this is a Unity bug.

The cause: ScrollRect.LateUpdate calls SetContentAnchoredPosition every frame with values between -0.003 ~ 0.003 when the scrollbar is hidden, even though velocity is zero.

The solution: subclass ScrollRect and ignore SetContentAnchoredPosition if the scrollbar is hidden.

Here is my subclass (supports vertical scrollbars only):

 using UnityEngine;
 using UnityEngine.UI;
 
 public class NWScrollRect : ScrollRect {
     /// <summary>
     /// ScrollRect.LateUpdate calls this function with very tiny values every frame,
     /// only if scrolling is not needed and even when velocity is zero.
     /// This makes text jitter. Check before setting position.
     /// </summary>
     protected override void SetContentAnchoredPosition(Vector2 position) {
         if (Application.isPlaying && verticalScrollbar != null && !verticalScrollbar.IsActive()) {
             if (content.anchoredPosition != Vector2.zero) {
                 position = Vector2.zero;
             } else {
                 return;
             }
         }
 
         // fires every frame in editor, but without this text jitters
         if (position != Vector2.zero && Approximately(content.anchoredPosition, position) 
             && Approximately(position, Vector2.zero)) {
             position = Vector2.zero;
         }
         
         base.SetContentAnchoredPosition(position);
     }
 
     /// <summary>
     /// Called when scrolling would occur.
     /// Prevent setting when vertical scrollbar is disabled and scrolling is not needed to prevent jittering.
     /// </summary>
     protected override void SetNormalizedPosition(float value, int axis) {
         if (Application.isPlaying && verticalScrollbar != null && !verticalScrollbar.IsActive()) {
             return;
         }
         base.SetNormalizedPosition(value, axis);
     }
     
     private static bool Approximately(Vector2 vec1, Vector2 vec2, float threshold = 0.01f) {
         return ((vec1.x < vec2.x) ? (vec2.x - vec1.x) : (vec1.x - vec2.x)) <= threshold
             && ((vec1.y < vec2.y) ? (vec2.y - vec1.y) : (vec1.y - vec2.y)) <= threshold;
     }
 }
 
Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Lashawn · May 03, 2019 at 07:10 PM 0
Share

Im having the same issues, however i don't exactly understand that your solution can you explain

avatar image sarahnorthway Lashawn · May 03, 2019 at 08:55 PM 0
Share

I've added my code for you. I'm still hoping this will be fixed in a future version of Unity (I haven't checked 2019 yet) or that I'll find some less hacky solution in the future.

avatar image Lashawn sarahnorthway · Jun 26, 2019 at 01:07 AM 0
Share

Oh wow thank you very much where should i put this script on my scroll rect parent game object?

avatar image UnrealTati · Aug 10, 2021 at 06:42 PM 0
Share

If you are having jitters on mobile, all you have to do is...

Application.targetFrameRate = 60;

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

257 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Invert UI scrolling 1 Answer

Music playing from 2 different scenes - how to fix? 1 Answer

Changing Scenes with a Button 1 Answer

Trouble with GUI Button Level switching. 0 Answers

Scroll Rect doesn't work when you have UI with click events on them. 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges