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
0
Question by areFranz · Apr 12, 2015 at 06:44 AM · c#errormaccoroutinesnested

Error with nested coroutines

Hi All! I have a problem with a nested coroutine. I have a FileasAndFolders class that crates in the 3D scene a empty game object witch contains a series of icons for files and folders of the desktop of my mac. And sort of filevrowser in 3D. To navigate in and out the folders i use some coroutines (in the class IconClick that is attached to any icon in the scene), The problem is that this coroutine (that creates the object and the icons) works perfectly:

     IEnumerator Load ()
     {
         showMenu = false;
 
         Vector3 target = new Vector3 (0, 0, -50);
 
         while (Vector3.Distance (cam.transform.position, target) > 0.25f) {
 
             cam.transform.position = Vector3.Lerp (cam.transform.position, target, Time.deltaTime * 5f);
             cam.transform.rotation = Quaternion.identity;
             yield return null;
         }
 
         GameObject content = GameObject.FindWithTag ("content");
         Destroy (content.gameObject);
 
         DeskState.SetLastPath (DeskState.GetPath ());
         DeskState.SetPath (DeskState.GetPath () + "/" + this.name);
         FindObjectOfType <FoldersAndFiles> ().PopulateMainSpace (DeskState.GetPath ());
     }

But the PreviousFoler coroutine returns me lots of empty objects with deifferent folders shown:

     IEnumerator PrevFolder ()
     {
         Vector3 target = new Vector3 (0, 0, -50);
         
         while (Vector3.Distance (cam.transform.position, target) > 0.25f) {
             
             cam.transform.position = Vector3.Lerp (cam.transform.position, target, Time.deltaTime * 5f);
             cam.transform.rotation = Quaternion.identity;
             yield return null;
         }
 
         GameObject content = GameObject.FindGameObjectWithTag ("content");
         Destroy (content.gameObject);
 
         string prevPath = Directory.GetParent (DeskState.GetPath ()).FullName;
         DeskState.SetPath (prevPath);
 
         FindObjectOfType <FoldersAndFiles> ().PopulateMainSpace (DeskState.GetPath ());
     }

If i delete the first while loop all it's ok but not animated... Any suggestion?

PS The DeskState class is a static class that I use to store the current visible folder path and the last showed path.

Comment
Add comment · Show 6
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 Tomer-Barkan · Apr 12, 2015 at 07:16 AM 0
Share

Show us how you call these coroutines

avatar image areFranz · Apr 12, 2015 at 04:06 PM 0
Share

So, the coroutines are called by:

     void Update ()
     {
         if (Input.Get$$anonymous$$eyDown ($$anonymous$$eyCode.Backspace) && DeskState.GetPath () != Environment.GetFolderPath(Environment.SpecialFolder.Desktop)) {
             StartCoroutine (PrevFolder ());
         }
     }
 

And by a button in a GUI:

     void OnGUI ()
     {
         GUI.skin = skin;
 
         float width = Screen.width * 0.5f;
         float height = Screen.height * 0.5f;
 
         if (show$$anonymous$$enu) {
 
             GUI.BeginGroup (new Rect (width - 256, height, 512, 256));
 
             GUI.Box (new Rect (0, 0, 512, 256), this.name);
             if(GUI.Button (new Rect (128, 112, 256, 32), "Open")) {
 
                 if (this.tag == "folder") {
 
                     StartCoroutine (Load ());
                 
                 } else if (this.tag == "file") {
 
                     Process.Start (DeskState.GetPath () + "/" + this.name);
                 }
             }
 
             if (GUI.Button (new Rect (128, 160, 256, 32), "Back")) {
 
                 StartCoroutine (JumpBack ());
             }
 
             GUI.EndGroup ();
         }
     }
avatar image areFranz · Apr 12, 2015 at 04:08 PM 0
Share

Sorry I forget... The first coroutine is called only if the folder is "Desktop" because i don't want to show previuos folders and this script is attached to every icon.

avatar image Tomer-Barkan · Apr 12, 2015 at 06:27 PM 0
Share

I don't really understand what's going on, but your scripts seem ok, no problems that I can tell. Try adding debug logs in the while loop that doesn't work, maybe that'll give you an idea as to what's going on. Print the camera's position, the target, etc.

avatar image areFranz · Apr 12, 2015 at 10:09 PM 0
Share

I forget another thing... The scene is built by:

  • Empty Object "Content $$anonymous$$anager" with attached the script "FolderAndFiles.cs (That contains the Populate$$anonymous$$ainSpace(strig path) function, that creates an empty game object with the icons prefabs as child)

  • the relative "Content" empty object created by that function

  • the Camera with attached the Camera$$anonymous$$otion.cs class that makes the camera move around the space

  • the Structure game object that contains ad childs the six walls of the main cube

I've noticed that if i call Laod() and PrevoiusFolder() coroutines without moving the camera in the space with the mouse wheel, everything works, but if I load a folder, then move forward with $$anonymous$$ouseScrool Wheel, when i press "Backspace" key, somewhat creates more than one Content game object, the first with the Desktop icons, the second with the previous folder (personal folder), the third with the other previous folder (users folder) and the fourth with root folder...all with a "Null reference exception " error at line

 string prevPath = Directory.GetParent (DeskState.GetPath ()).FullName;

The error is "Object reference not set to an instance of an object" I think that it could be an error due to the line:

 if (Input.Get$$anonymous$$eyDown ($$anonymous$$eyCode.Backspace) && DeskState.GetPath () != Environment.GetFolderPath(Environment.SpecialFolder.Desktop))

and the time that the first whlie loop of PreviuosFolder() coroutine need to be completed... But how i can adjust that?

Show more comments

0 Replies

· Add your reply
  • Sort: 

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

Distribute terrain in zones 3 Answers

Multiple Cars not working 1 Answer

Coroutine stops after any yield statement halfway through 0 Answers

Unity Follow backward 1 Answer

the name admob does not exist in the current context. 2 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