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
1
Question by Julian Witte · Oct 21, 2010 at 08:12 PM · scrollviewstackbeginscrollview

Problem with ScrollView

I am getting the error "Operation is not valid due to the current state of the object System.Collections.Stack.Peek ()" while building and animating a GUI accordion for smooth moviment using scrollview. What could be happening?

Thanks in advance.

Here is the Code:

void OnGUI() { GUISkin skin = GUI.skin; GUI.skin = sknScrollbar; if (this.Display) { GUILayout.BeginArea(this.rtComponentPosition); vtScroll = GUILayout.BeginScrollView(vtScroll, GUILayout.Height(Screen.height - rtComponentPosition.yMin), GUILayout.Width(this.rtComponentPosition.width)); ListChilds(root.childs); GUILayout.EndScrollView(); GUILayout.EndArea(); } GUI.skin = skin; }

void ListChilds(IList<Item> childs) { foreach (Item item in childs) { item.scrollHeight = getScrollSize(item); if (item.Nome == "PINTAR" || item.Nome == "DECORAR") { accordionSize = 29; } else accordionSize = 25;

     if (item.Nome == currentItem)
     {

         GUILayout.BeginScrollView(new Vector2(), GUILayout.Height(accordionHeight));
         if (item.isOpened &amp;&amp; !item.closening &amp;&amp; accordionHeight &lt; accordionSize * (1 + item.childs.Count))
         {
             accordionHeight += 2;
         }

         if (item.closening == true &amp;&amp; accordionHeight &gt; 29)
         {
             accordionHeight -= 2;
         }
         if (item.closening == true &amp;&amp; accordionHeight &lt;= 29)
         {
             item.isOpened = false;
             item.closening = false;
         }

     }

     if (GUILayout.Button(item.Nome, item.style))
     {

         if (item.isOpened == false)
         {
             item.isOpened = true;
         }
         else
         {

             item.closening = true;
         }

         item.SetClick();
     }

     if ((item.childs != null) &amp;&amp; (item.isOpened))
         ListChilds(item.childs);


     if (item.Nome == currentItem)
     {
         GUILayout.EndScrollView();
     }

}

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

2 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by Antares19 · Jan 14, 2013 at 07:05 PM

Julian, your hint helped alot! Thank you.

I've encountered same nasty bug with "GUILayout.BeginHorizontal". Spend few hours in debugging before figured out the source of the problem. After finding your answer here, I ended up with code like this:

 GUILayout.BeginHorizontal(); 
 bool isHorizontalBlockActive = true; 
     
 if(GUILayout.Button("Start complex process"){    
     MyComplexProcess();    
     isHorizontalBlockActive = false;             
 }
 
 // ...more buttons here
  
 if(isHorizontalBlockActive)
     GUILayout.EndHorizontal();

Looks ugly, but works fine :)

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 nicloay · Mar 08, 2013 at 01:00 PM 0
Share

heh.. it's good when you have all your code in one class. And it doesn't work for my custom component.

     void OnGUI () {    
         
         showAllSprites ();
         
     }
     
     void showAllSprites ()
     {
         EditorGUILayout.BeginHorizontal();    
         bool horizontalActive=true;
         
         e1 = UFTEditorGUILayout.showAtlasEntryGUI(atlas$$anonymous$$etadata,e1, GetInstanceID());                    
         e2 = UFTEditorGUILayout.showAtlasEntryGUI(atlas$$anonymous$$etadata,e2, GetInstanceID());            
         
         if (horizontalActive)
             EditorGUILayout.EndHorizontal();
     }


here is my code, and anyway i'm getting this error, on if(horizontalActive) block

avatar image mikeschuld · Sep 17, 2013 at 02:35 AM 0
Share

You are never setting horizontalActive to false anywhere in your code. In the code you posted the two lines you added don't actually change anything.

avatar image nicloay · Sep 17, 2013 at 03:04 AM 0
Share

mikeschuld, UFTEditorGUILayout.showAtlasEntryGUI has a lot of calls of different GUILayout methods inside. Sorry, but i don't remember how did i solve my problem.

avatar image
1

Answer by Julian Witte · Oct 22, 2010 at 05:47 PM

Well, I found out what was happening. the "item.SetClick();" changes the currentItem string, and doing that, the condition is true for the EndScrollView() before the BegingScrollView exists, as it tries to End something that doesn't yet exists, the error is returned.

I fixed the problem adding a bool to the End condition that is false on SetClick() and only is only set true after BeginScrollView().

Hopes it helps anyone someday...

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to put gameObject in ScrollView window 0 Answers

GUI.BeginScrollView - How to customize the vertical scroller to add padding. 0 Answers

Custom Editor for C# Dictionary 2 Answers

Editor Crashes when spawning 1k objects 2 Answers

How can I assign a UI text and a sprite to variables? 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