Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 genaray · Sep 08, 2019 at 06:25 PM · unity 5uiphysicsuser interfacescrollview

Scroll rect - Repositioning elements causes scroll velocity to sky rocket ?!

Good evening,

im working on a leaderboard for my little mobile game. This leaderboard should fetch scores from my server, this requires a modified scroll rect aswell as recycling elements.

Recycling works fine so far, except one detail... the velocity while scrolling... when the user scrolls trough the list in little "steps / intervalls", my scroll rects repositions elements just fine and the velocity dont cause any problems.

But once the user drags the list for a longer duration while existing elements are getting recycled and repositioned, the velocity skyrockets... this causes the list to jump to the bottom everytime it recycled existing elements, which loads new scores from the server like a machine gun....

Heres a link to a visual representation of the velocity skyrocket i encountered : Velocity sky rockets, causing the list to load elements too fast

I tested this strange behaviour with a normal implementation of a scroll rect... no problems here... but once we actually relocate those elements, this strange behaviour starts to occur.

Heres my implementation of the scroll rect modifier script :

 public ScrollRect scrollRect;
 public RectTransform content;
 
 /// Gets called once we received packets from the server.
 protected override void received(ISFSObject packet) {
 
        float totalsize = 0;
 
        ISFSArray scores = packet.GetSFSArray(validMessage());
        for (int index = 0; index < scores.Count; index++) {
 
            /// Extracting stuff from packet and initialse the element.
            UIElement element = initialiseElement(ID, username, scoreAmount);
 
            /// Calculating the size for each entry, for getting a total size.
            RectTransform rectTransform = element.GetComponent<RectTransform>();
            totalsize += rectTransform.rect.height;
        }
 
        /// When there more than 50 entrys in the list, start to recycle the top ones.
        if (elements.Count > maximum) {
 
            Canvas.ForceUpdateCanvases();
 
            /// Content is the gameobject-parent of the scroll view elements.
            /// Adjusting the y position of the content, otherwhise it would either be pushed up or down, this works fine.
            content.offsetMax = new Vector2(0, content.offsetMax.y - totalsize);
        }
    }
 
 
    ///////////////////////
    ///  Main methods
    ///////////////////////
 
 
    /// <summary>
    /// Creates a leaderboard-score element in the list to display the progress of a user.
    /// Either recycles it or creates a fully new one.
    /// </summary>
    /// <param name="name"></param>
    /// <param name="score"></param>
    public UIElement initialiseElement(int index, string name, long score) {
 
        /// If there more than 50 elements, recycle one.
        if (elements.Count > maximum) {
 
            int use = scrollingDown ? 0 : content.childCount - 1;
            int oldIndex = 0;
 
            /// Receiving either first or last child for recycling it.
            LeaderboardElement leaderboardElement = content.GetChild(use).GetComponent<LeaderboardElement>();
            oldIndex = leaderboardElement.getIndex()-1;
            /// Setting it to a new position.
            leaderboardElement.transform.SetSiblingIndex(index);
 
            Canvas.ForceUpdateCanvases();
            return leaderboardElement;
        }
        else {
 
            /// Creates a new one.
            GameObject leaderboardEntry = Instantiate(this.leaderboardElement, this.content, false);
            leaderboardEntry.transform.SetSiblingIndex(index);
 
            Canvas.ForceUpdateCanvases();
            return leaderboardElement;
        }
    }
 
 
    /// <summary>
    /// Gets called during scrolling the ledaderboard scores for loading new ones, listener of scrollRect.onValueChanged();
    /// </summary>
    /// <param name="position"></param>
    public void onScroll(Vector2 position) {
 
        scrollingDown = lastPosition <= content.offsetMax.y;
        lastPosition = content.offsetMax.y;
 
        if (bottom || top) return;
        if (elements.Count < maximum && content.childCount <= 0) return;
 
        float totalHeight = content.sizeDelta.y;
        float difference = content.rect.height - totalHeight;
 
        if (content.offsetMax.y+difference >= content.rect.height - ((content.rect.height / 100) * 20)) {
 
            if (!bottom && onEnd != null) {
                /// Load new ones from the server... once those arrive, received() is getting called.
                bottom = true;
            }
        }
    }


Did anyone ever had a similar problem ? Or does someone know what i actually need to do for fixing this annoying issue ?

Im glad for everyhelp i can get to solve this issue, thanks !

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
0

Answer by JonPQ · Sep 09, 2019 at 06:34 PM

sounds like dragging the Ui and moving recycled elements causes a large positional shift in the scroll window, and probably therefore causes same shift in velocity. You might want to try logging velocity changes, and see if you can figure out how much it changes by whenever you recycle a scroll element in the hierarchy. You might be able to subtract that from the velocity delta.

Comment
Add comment · 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

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

394 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 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

Control ScrollView with arrow keys? 3 Answers

Combine text and buttons in scroll rect 0 Answers

Unity UI Interactivity Bugs - Have to press ESC between every action 0 Answers

i need help with uGUI Scrollview!!! 0 Answers

UI Scroll View - Scrollbar only working on one half 1 Answer


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