Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
4
Question by Sabikku · Oct 01, 2014 at 08:22 PM · uiscrollingscrollbar

Force ScrollBar to scroll down with ScrollRect

Hi. I'm keeping a expandable list of elements within my ScrollRect and I'm trying to automaticly scroll to the bottom of the rect each time a new element is added.

First I thought it should be done this way:

 scrollRect.verticalScrollbar.value = 0;

But it did nothing, literally the scrollbar didn't change its value. So... the ScrollRect class sets the value of the scrollbar by itself. In this case I tried to set it with the ScrollRect instance:

 scrollRect.verticalNormalizedPosition = 0;
 

But each time this line is executed, I get the error:

 UnassignedReferenceException: The variable m_ViewRect of ScrollRect has not been assigned.
 You probably need to assign the m_ViewRect variable of the ScrollRect script in the inspector.

I'm assured I have set up the "content" and "vertical scrollbar" properties of ScrollRect in inspector. Any ideas what am I doing wrong?

Just to be sure, some logs:

 scrollRect.verticalScrollbar.value = 0.5f;
 Debug.Log( scrollRect.verticalScrollbar.value ); => 0.5
 Debug.Log( scrollRect.verticalNormalizedPosition ); => 0
 // even after those lines value of the scrollbar in the inspector is still set to 1
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

6 Replies

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

Answer by frankcyli · Aug 05, 2015 at 09:47 PM

Works for me in Unity 5.1:

GameObject.Find ("Scroll Rect").GetComponent<ScrollRect>().verticalNormalizedPosition = 0.5f;

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 Fattie · Feb 21, 2016 at 02:24 AM 0
Share

This now works perfectly (2016) in all Unity.

avatar image
14

Answer by wowipop · Oct 14, 2014 at 09:51 AM

 Canvas.ForceUpdateCanvases();
 scrollRect.verticalScrollbar.value=0f;
 Canvas.ForceUpdateCanvases();

well the first Canvas.ForceUpdateCanvases() is a must.. the second one just depend on what you do

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 sudhir_kotila · May 14, 2016 at 06:46 AM 0
Share
  Canvas.ForceUpdateCanvases();
  scrollRect.verticalScrollbar.value=0f;
  Canvas.ForceUpdateCanvases();

This code is perfectly works and it's very useful for automatically scrolling(vertical scrollbar).

avatar image penta_d · Sep 29, 2016 at 06:30 AM 0
Share

This works for me. Thank You :)

avatar image MileSplit · Oct 13, 2016 at 05:30 PM 0
Share

Wow thank you, nothing else was working, but the

 Canvas.ForceUpdateCanvases();

Works really well.

avatar image
5

Answer by Rosecroix · Dec 02, 2014 at 09:52 PM

A much simpler solution is to do a

     yourScrollRect.velocity=new Vector2(0f,1000f);

But I agree it would be more intuitive to change the scrollbar value, that was what I tried first too.

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 Kuerbiskerngwendoline · Aug 22, 2015 at 08:20 AM 0
Share

I don't think changing the scrollbar value would be a more intuitive solution as it is not required to set a scrollbar. So if you don't have one it will give a null pointer exception.

avatar image Sargonius · Dec 18, 2015 at 12:45 PM 0
Share

Perfect solution! Thank you!

avatar image Fattie · Feb 21, 2016 at 02:24 AM 0
Share

This does work - you can set the velocity (perhaps continuously in a coroutine, say) if you want to. You'd have to continually check it has not got to where you want it to go. It seems much easier to just trivially tween the .verticalNormalizedPosition to whatever position you want.

avatar image
3

Answer by cdpatel · Dec 28, 2016 at 08:39 AM

Try it. It is work for me.

Canvas.ForceUpdateCanvases ();

messageScrollRect.verticalNormalizedPosition =0f;

Canvas.ForceUpdateCanvases ();

Comment
Add comment · Show 2 · 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 CrushedPixel · Jun 18, 2017 at 07:30 AM 0
Share

This actually worked better for me than the other suggestions. Thanks!

avatar image HansDong · Oct 22, 2017 at 09:10 AM 0
Share

Thank you veryyyyyy much... It really works better than the other suggestions.

avatar image
1

Answer by dendriel · Jul 26, 2017 at 10:21 PM

Using Unity 5.6 my verticalNormalizedPosition can't be set to 0. That is, it is set to zero but looks like to update right after.

Thus, the verticalNormalizedPosition can't be set to round zero and for long messages some lines won't be visible.

To solve this "overwriting", it's necessary to wait for the canvas to update with a "yield return null".

 Canvas.ForceUpdateCanvases();
 
 // Wait.
 yield return null;
 
 scrollElem.verticalScrollbar.value = 0f;
 Canvas.ForceUpdateCanvases();
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
  • 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

20 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

Related Questions

The Unity Scrollbar Handle NaN problem 0 Answers

ScrollRect resetting scroll position on content change 6 Answers

Scrollbar scrolling in the opposite direction 1 Answer

Scrolling Inventory - Instantiate Buttons Too Slow [UI 4.6] 2 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