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 /
avatar image
3
Question by patrik-org · May 22, 2016 at 04:23 PM · uipanelscrollingscrollbar

ScrollRect resetting scroll position on content change

Is there a way to tell ScrollRect not to reset scroll position when content changes? The scrollable content size changes during runtime as items are added and removed - problem is that the scroll position is reset whenever the content rect transform is changed. I want the scroll position to remain. Is there a way to do this?

Comment
Add comment · Show 1
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 Brogan89 · Jul 25, 2017 at 01:18 AM 0
Share

I am also wondering this, did you solve it? I tried getting currentPos then applying currentPos within an event. But this caused the scrollRect to snap to top and then snap back to position... obviously not ideal

6 Replies

· Add your reply
  • Sort: 
avatar image
7

Answer by Brogan89 · Jul 25, 2017 at 02:33 AM

I found the problem. Having any kind of layout group of the view port will change the behaviour when objects are added to the content pragmatically. Also making sure the Contents anchor points and pivot are set correctly. For a Vertical scrollRect you want them to be like this alt text


recttransform-anchors.png (2.6 kB)
Comment
Add comment · Show 1 · 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 SimRuJ · Dec 10, 2021 at 01:30 PM 0
Share

What OP described seems to be default behavior in Unity 2021 and if you don't want the Scroll View to remember the position, then you have to use scrollView.GetComponent<ScrollRect>().verticalNormalizedPosition = 1f; (1=top, 0=bottom). Btw, the pivot is set to x=0 & y=1 by default for all of my "content" objects and I haven't noticed any problems with wrong alignment so far.

avatar image
1

Answer by vverma9 · Jul 16, 2018 at 11:32 AM

This worked for me, attached this to the scrollbar

 void OnEnable()
 {
     StartCoroutine(resetScrollPos());
 }
 
 IEnumerator resetScrollPos()
 {
     yield return null; // Waiting just one frame is probably good enough, yield return null does that
     gameObject.GetComponent<Scrollbar>().value = 1;
 }



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
avatar image
1

Answer by steril · Jul 05, 2021 at 03:11 PM

Create a ScrollRectExtensions class

 public static class ScrollRectExtensions
 {
     public static float GetValue(this ScrollRect scrollRect, float value)
     {
         return scrollRect.horizontal ?
                 scrollRect.horizontalNormalizedPosition :
                 scrollRect.verticalNormalizedPosition;
     }
 
     public static void SetValue(this ScrollRect scrollRect, float value)
     {
         if (scrollRect.horizontal)
         {
             scrollRect.horizontalNormalizedPosition = value;
         }
         else
         {
             scrollRect.verticalNormalizedPosition = value;
         }
     }
 }

In your code, call:

 void Awake()
 {
             StartCoroutine(FixScrollRects());
 }
 
 IEnumerator FixScrollRects()
 {
             yield return new WaitForEndOfFrame();
             yield return new WaitForEndOfFrame();
             foreach (var scrollRect in GetComponentsInChildren<ScrollRect>())
             {
                 scrollRect.SetValue(0);
             }
 }

Double WaitForEndOfFrame(); was necessary in my case. (2019.3.1f)

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
avatar image
-1

Answer by Pundek · Nov 25, 2016 at 03:15 PM

did you solve the problem?

Comment
Add comment · Show 3 · 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 Pundek · Nov 25, 2016 at 03:25 PM 4
Share

hahah i just found a solution:`scroll.verticalNormalizedPosition = 1f;`

avatar image tyinunity Pundek · May 03, 2018 at 08:11 PM 2
Share

setting verticalNormalizedPosition worked for me; thanks!

note, per the docs:

The vertical scroll position is a value between 0 and 1, with 0 being at the bottom.

avatar image vverma9 tyinunity · Jul 16, 2018 at 11:15 AM 0
Share

it didn't work for me

avatar image
-1

Answer by yusuf91 · Mar 17 at 03:11 PM

I have the same issue, the images in my content reset when I pressed the play button, I use a VerticalLayyoutGroup, can anymore give me the solution, please? THX

Comment
Add comment · Show 1 · 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 SimRuJ · Mar 18 at 10:21 AM 1
Share

Why are you posting this as an answer? This doesn't answer anything and should be a comment!

  • 1
  • 2
  • ›

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

69 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

Related Questions

How can I create a Multi line Input Field with Scrollbar? 0 Answers

Changing the scale of the scroll view 1 Answer

How do I Make TextMeshPro InputField scroll through code? 0 Answers

Move Dropdown using arrow buttons 0 Answers

Scrollbar touch sensitivity 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