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
0
Question by Sixakoo_ · Jul 15, 2011 at 02:50 AM · guibuttonarrayloophang

Unity Hangs/Crash when remove GUI Button.

Quick question here. I write a loop in my GUI script and turn out okay when I attach it to a GUI button. As I remove the button so that it would appear straight away, unity hangs. Is there an error in my script? Thank You.

The part of the code:-

 if(GUILayout.Button("Add"))
     {
         selStrings = new Texture[StackNum];
 
         for (i = 0 ; i < selStrings.length ; i++)
         {
             selStrings[i] = new Texture2D(60,80, TextureFormat.RGB24, false);
             www = new WWW("file://" + Application.dataPath + "/Screenshots/ScreenShot" + i + ".png");
             www.LoadImageIntoTexture(selStrings[i]);
             
             TextureScale.Bilinear (selStrings[i],133,100);
             Debug.Log(i);
         
         }
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
1
Best Answer

Answer by Waz · Jul 15, 2011 at 03:09 AM

Is it hanging or just going extremely slow? If you do the above in OnGUI, it will be loading those images at least 2 times every frame.

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 Sixakoo_ · Jul 15, 2011 at 03:16 AM 0
Share

I guess it's going extremely slow. Why would it be loading twice on every frame but reacts differently when I put a button? Would you care to explain? Sorry for the noobness.

avatar image Bunny83 · Jul 15, 2011 at 03:21 AM 0
Share

It would load them only once since Button only return true in the repaint step and only for one frame, but i guess the problem ist that you don't wait until the WWW request is finished. The WWW class works completely asynchron.

avatar image Sixakoo_ · Jul 15, 2011 at 03:35 AM 0
Share

Oh I see. I did remove the yield for the WWW. Thank you very much for the explanation.

avatar image
1

Answer by Bunny83 · Jul 15, 2011 at 03:32 AM

From the script part you're showing i can't determine what language you're using but i guess it's UnityScript.

 function LoadImages()
 {
     selStrings = new Texture[StackNum];

     for (i = 0 ; i < selStrings.length ; i++)
     {
         selStrings[i] = new Texture2D(60,80, TextureFormat.RGB24, false);
         www = new WWW("file://" + Application.dataPath + "/Screenshots/ScreenShot" + i + ".png");
         
         yield www; // this is important! It will suspend this coroutine until the "download" is finished
         
         www.LoadImageIntoTexture(selStrings[i]);

         TextureScale.Bilinear (selStrings[i],133,100);
         Debug.Log(i);
     }
 }

 function OnGUI()
 {
     if(GUILayout.Button("Add"))
     {
         LoadImages();
     }
 }
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 Waz · Jul 15, 2011 at 03:35 AM 0
Share

@Bunny83, is there an answer in there? Looks like you got half way through saying something.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Creating GUI Buttons with a for loop from an array 6 Answers

Dynamically set the sprite of a button in loop 0 Answers

Trying to get an array to make working buttons. [Script Update] 2 Answers

Making a set of buttons from an Array 1 Answer

change texture of GuiButton in for loop 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