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 /
avatar image
1
Question by SteenPetersen · Aug 14, 2017 at 05:26 PM · guiscrollviewguilayout

GUILayout.BeginScrollView cant seem to change where the box I create is positoned.

Hi I am trying to make a chat window for my multiplayer Game. I have done everything except for the fact that the window where the text is placed is always in the top left hand corner of the screen and it is driving me nuts.

 Vector2 scrollPosition = new Vector2(5698, 312);  // I have put an abstract value here to show that this values does not matter at all and no matter what value I write here it does the same thing.

// and this is the text inside OnGui()

     scrollPosition = GUILayout.BeginScrollView(scrollPosition, GUILayout.Width(450), GUILayout.Height(450));
     
             foreach (var cm in chatHistory)
             {
                 GUILayout.Label(cm);
             }
     
      GUILayout.EndScrollView();
 

This bow always ends up being placed in the top left hand corner of the screen and I do not understand why. how can I tell the Scrollview to have a certain x and Y coordinate and a certain width and height.

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
1
Best Answer

Answer by Bunny83 · Aug 14, 2017 at 09:41 PM

A ScrollView is also a layouted gui element when you use the GUILayout version. Like any GUILAyout element you never explicitly specify the position. Every element gets it's position and size from the layoutsystem.

One way is to use a horizontal and a vertical layout group and use a Space before the ScrollView. However that might be a bit too complicated for your case. If you just want to specify where a certain layour group should be positioned you can use GUILayout.BeginArea and GUILayout.EndArea around your ScrollView. In BeginArea you have to specify a screen rect. Everything between BeginArea and EndArea will be layouted seperately.

The Scroll position only controls the scroll offset of the child objects of the ScrollView. Though you can only scroll when the child objects would overflow the scrollview area. The same way your browser won't allow any scrolling then the whole website fits onto the screen / window.

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 SteenPetersen · Aug 15, 2017 at 04:32 AM 0
Share

Hi Bunny and thank you for answering my question - before I accept it as correct I just want to make sure I get everything clear - I have wrapped my code with the "beginarea" and have been able to position it where I want it. What I dont fully understand is your last paragraph and the reason as to why I cannot scroll now. I have made the "scrollview" the same size and the scrollbar does appear, but it wont scroll up. I do have a Peice of code that forces it down but it doesnt seem to be affecting it in anyway in this case. Have tried commenting it out with no change.

here is the relevant code now with your input:

  Vector2 scrollPosition = new Vector2(0, 0);  // variable      
 
 
  GUILayout.BeginArea(new Rect(0, Screen.height - 255, 450, 222));
 
         scrollPosition = GUILayout.BeginScrollView(new Vector2(0, Screen.height -255), GUILayout.Width(450), GUILayout.Height(222));
 
         foreach (var cm in chatHistory)
         {
             GUILayout.Label(cm);
         }
 
 
         GUILayout.EndScrollView();
 
         GUILayout.EndArea();
 
         current$$anonymous$$essage = GUI.TextField(new Rect(0, Screen.height - 25, 450, 25), current$$anonymous$$essage);
         current$$anonymous$$essage = Regex.Replace(current$$anonymous$$essage, @"[^a-zA-Z0-9/ ]", "");

avatar image Bunny83 SteenPetersen · Aug 15, 2017 at 10:40 AM 0
Share

You currently use a fix scroll position. You pass in

 new Vector2(0, Screen.height -255)

So the scroll view will always show the same part. In your original code you correctly pass scrollPosition .

avatar image SteenPetersen Bunny83 · Aug 16, 2017 at 06:52 AM 1
Share

Fantastic thanks for the help and good explanation.

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

111 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

Related Questions

How to change thickness of ScrollBar of GUILayout ScrollView? 0 Answers

Invisible BeginScrollView thumb 0 Answers

GUIlayout scrollbar, Not working well... 1 Answer

ScrollView - How to stop infinite scrolling? 1 Answer

ScrollWindow AutoUpdating value help :( 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