Hello, I am trying to place a GUI Window inside a scroll view so that the window will move when when the scroll view is scrolled. My code is basically
scrlpos = GUI.BeginScrollView( ... );
GUI.Window ( ... );
Currently it seems that it may not be possible to achieve the effect I want with a GUI.Window. Is there any way? Thanks.
An update: I have still had no luck. I am tempted to either use my own GUI dragable box function, although that will be a pain as well as you'd also have to change the GUI style when it is selected. My other idea is to offset the GUI window by the scroll view position in accordance to the scroll view's rects. This would also be very annoying.
Answer by Dreamora
Jul 10, 2011 at 11:11 PM
GUI.Window are completely seperate containers and form a container for all the rest, they can't be contained in anything else aside of OnGUI itself
Depending on what you want to do in detail, BeginArea / BeginGroup are what you might actually be looking for (subcontainer within another container like a scrollview)
Answer by jahroy
Jul 11, 2011 at 05:36 AM
Here's a thought that I can't test at the moment....
You could write a function that 'clamps' the window's position rectangle so that it's always within the scroll view rectangle.
You could alter the position of the rectangle based on the value of the scroll vector (or by dragging it), then call your clamp function.
Answer by GXMark
Nov 17, 2012 at 03:25 PM
If you want to
a. instance a GUI.Window b. scroll the window both vertically and horizontally c. make the window dragable
then read this code
public Vector2 scrollPosition = Vector2.zero;
// Required so that all GUI Controls render relative to (0,0) inside the window
// Call the window
windowRect = GUI.Window(0, windowRect, DoMyWindow, "Inventory");
private Vector2 scrollViewVector = Vector2.zero;
void DoMyWindow(int windowID)
// Begin the ScrollView (First Rect defines the size of the scrollview, Second Rect defines the size of the view of controls
// If the size of your controls dont fit into the size of your scrollview then horizontal or vertical scrollbars appear
scrollViewVector = GUI.BeginScrollView (new Rect (0, 20, inventory_width-5, inventory_height-25), scrollViewVector, new Rect (0, 0, 0, top_offset+entry_pos+25));
// My Controls (Put what you like in here)
// End the ScrollView
// Add this line to make the window dragable
GUI.DragWindow (new Rect (0,0, 10000, 20));
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a site navigation guide.
If you are a new user to Unity Answers, check out our FAQ for more information.
Make sure to check out our Knowledge Base for commonly asked Unity questions.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
Answers and Comments
5 People are following this question.
Text Asset not displaying correctly.
Suppress Horizontal Scrollbar?
unity3d new UI - spacing in Scrollable items does not scale proportionally.
How can I combine a Mask with a Scroll Rect to limit the visible content?
GUI ScrollView doesn't work with GUI.matrix