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
2
Question by ks13 · Dec 22, 2011 at 10:10 AM · updateonguiboolvaluesdifference

Bool returns different values in Update and OnGUI

Hello, i'm having a problem that's giving me headache :
when i check the value of a bool in Update, it returns False, but in OnGUI i get a True. Here's the code which contains different variables i added for checking the returns, among which the int "count" that only counts up to 139 then stops for some reason.

     public class LoadGallery : MonoBehaviour {
         public Params pars = null;
         public List<GameObject> galleryObjectsToSpawn = null;
         public GameObject[] galleryFrameworksToSpawn = null;
         private GameObject[] galleryObjects = null;
         private WWW tmp = null;
         private bool replaced = false;
         private string output = null;
         private string done = null;
         private int count = 0;
     
     void Start () {
         Debug.Log("Starting");
         pars = (Params)FindObjectOfType(typeof(Params));
         foreach (var item in galleryObjectsToSpawn)
         {
             if (Instantiate(item) == null)
                 Debug.Log("Error : couldn't create " + item.name);
         }
         galleryObjects = new GameObject[galleryFrameworksToSpawn.Length];
         GameObject obj;
         for (int i = 0; i < galleryFrameworksToSpawn.Length; i++)
         {
             if ((obj = (GameObject)Instantiate(galleryFrameworksToSpawn[i])) == null)
                 Debug.Log("Error : couldn't create " + galleryFrameworksToSpawn[i].name);
             else
             {
                 galleryObjects[i] = obj;
                 StartCoroutine(pars.GetAssetBundle(pars.Country + ".unity3d"));
                 StartCoroutine(pars.GetTexture("Mini/" + pars.Country + "/" + pars.Country.ToLower() + "_" + (i + 1).ToString() + "__main_mini.jpg", obj));
             }
         }
         Debug.Log("Done");
     }
 
     void Update()
     {
         if (tmp == null)
         {
             tmp = pars.Assets[pars.Country + ".unity3d"];
             output = tmp.url;
         }
         else if (tmp.isDone && !replaced)
         {
             for (int i = 0; i < galleryObjects.Length; i++)
             {
                 galleryObjects[i].renderer.material.mainTexture = (Texture2D)Instantiate(tmp.assetBundle.Load(pars.Country.ToLower() + "_" + (i + 1).ToString() + "__main.jpg"));
                 galleryObjects[i].transform.Rotate(new Vector3(0, 0, 45));
                 output = (i + 1).ToString() + " - " + galleryObjects[i].renderer.material.mainTexture;
             }
             //tmp.Dispose();
             //pars.Assets.Remove(pars.Country + ".unity3d");
             replaced = true;
         }
         if (tmp != null)
         {
             done = tmp.isDone.ToString();
             count += 1;
         }
     }
 
     void OnGUI()
     {
         if (tmp != null)
         {
             if (tmp.isDone)
                 GUI.Label(new Rect(0, 100, 500, 25), "Done loading the images " + tmp.isDone + " and replacing " + replaced + " count " + count);
             else if (tmp.error != null)
                 GUI.Label(new Rect(0, 100, 500, 25), tmp.error);
             else
                 GUI.Label(new Rect(0, 100, 500, 25), (tmp.progress * 100).ToString() + "%");
 
         }
         if (output != null)
             GUI.Label(new Rect(0, 200, 500, 25), output);
         if (done != null)
             GUI.Label(new Rect(0, 225, 500, 25), done);
     }
 }

The bool giving different results is tmp.isDone. On every try it shows the "Done loading the images" message, but won't go into the loop to place them on the objects. Also, i use another script for downloading bundles :

 private Dictionary<string, WWW> abDic = new Dictionary<string, WWW>();
 
 public Dictionary<string, WWW> Assets
     {
         get { return abDic; }
     }
 
 public IEnumerator GetAssetBundle(string url)
     {
         WWW ab;
         abDic.Add(url, (ab = new WWW(url)));
         yield return ab;
         
     }

the dictionary being private is to avoid it being showed in the Editor. Does anyone have an idea as to why the bool is returning different values?

Comment
Add comment · Show 1
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 ks13 · Dec 22, 2011 at 11:14 AM 0
Share

Ok, here's some additional info about the script's purpose and the infos i got after making other tests :
The goal of the script is to load thumbs/smaller version images (called $$anonymous$$i), so the user will be able to see the images till the AssetBundle is downloaded and the $$anonymous$$is are replaced with high quality images.
The part that's not working is replacing the $$anonymous$$is with the high quality images once the asset has finished downloading.
Since it's searching for local files as a WebPlayer, i didn't know how make it search for the files in editor so i was testing with an emulated server with EasyPHP and building the player to test every change.
When i tried the player in editor, of course it didn't find the files but tmp.isDone was giving the right value and didn't stop updating after a few seconds, contrary to the built player.

1 Reply

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

Answer by ks13 · Dec 22, 2011 at 02:18 PM

So, not sure if it's being drowsy this morning or due to fatigue but i totaly missed the big line in the middle of the loop :

 StartCoroutine(pars.GetAssetBundle(pars.Country + ".unity3d"));

Since it's the hihg quality images assetBundle, calling it's downloading more than once is weird, and pretty taxing on the system. After i moved it out of the loop the bool went back to giving correct values. What i don't understand is why it worked in the editor. Anyway, if anyone else got this problem, it might be the same case as mine.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

activating multiple voids with the same name trough one line 1 Answer

Bool not being re-triggered in FixedUpdate or Update 1 Answer

How does this script identify other players? C# 1 Answer

Change Bool When Audio Clip Ends C# 1 Answer

What is the difference between Update and LateUpdate?? 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