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 /
This question was closed Oct 15, 2013 at 10:56 AM by Fattie for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Croustibat · Oct 10, 2013 at 10:44 AM · instantiatecoroutineyieldsynchronizationresources.load

How to make a loading feedback for big GameObjects loading?

I already have one answer to a part of this question: by using the yield statement, for example:

 private var loading : boolean = false;
 function loadMyMesh()
 {
     loading = true;
     var myNewGO : GameObject = Instantiate(Resources.Load("models/bigbigmesh", GameObject));
     yield;
     loading = false;
     return myNewGO;
 }
 function OnGUI()
 {
     if (loading)
     {
         GUI.Box(Rect(0,0,50,10), "LOADING...");
     }
 }

This is the first time I use "yield", and I have not understood everything about coroutines yet. I'm not sure this is the best workaround for my problem, and whereas this code works fine in the editor, this doesn't work while deployed for the web player. If I try to load something on the web player, the object is loaded, then the message "loading..." appears for one frame, then disappears.

What am I doing wrong?

Comment
Add comment · Show 3
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 meat5000 ♦ · Oct 10, 2013 at 11:39 AM 0
Share

Add a timer or something to that effect that makes loading = false; after the period of time you choose.

$$anonymous$$aybe WaitForSeconds or something like that.

Seriously though, it won't take very long to Instantiate an Object.

avatar image Croustibat · Oct 10, 2013 at 12:00 PM 0
Share

Thank you for the answer In my case, it takes 1 to 3 seconds to load some of my models and I don't want the user to think that the application froze. I will try WaitForSeconds as you said, thank you.

avatar image Fattie · Oct 10, 2013 at 12:26 PM 0
Share

The issue is an extreme pain in the ass

http://answers.unity3d.com/questions/433609/hiccups-when-loading-images-from-resources-folder.html

http://answers.unity3d.com/questions/393460/resourcesload-async-for-large-images.html

the fact that you can't stream large stuff in to Unity (other than audio, which is handled perfectly) is a total pain in the ass.

2 Replies

  • Sort: 
avatar image
0
Best Answer

Answer by Croustibat · Oct 10, 2013 at 02:26 PM

Ok I got it working. This is the steps I followed:

  • you made me understand the following thing: at the line an Instantiate or a Resources.Load is called, no Update or OnGUI is called until it's done. That's why my line "loading = true;" was not taken into account in the OnGUI monobehaviour until the loading was done.

  • so, I changed my code to the following:

    function loadMyMesh() { loading = true; yield; var myNewGO : GameObject = Instantiate(Resources.Load("models/bigbigmesh", GameObject)); loading = false; return myNewGO; }

It's still working in the editor, but a strange problem came: the function "loadMyMesh" doesn't have the same behaviour when it is called by the navigator through javascript "SendMessage" (see [here][1]) as when the same function is bound to an event such as Input.GetKeyDown() In the first case, the yield; doesn't make any difference, whereas it's working fine when the function is bound to a keyboard event. To solve the problem with the least modifications, I first tried the meat500's solution, which worked out perfectly, thus I still don't really understand what's been going on. Anyway, here is my final code:

 function loadMyMesh()
 {
     loading = true;
     yield WaitForSeconds(.1);
     var myNewGO : GameObject = Instantiate(Resources.Load("models/bigbigmesh", GameObject));
     loading = false;
     return myNewGO;
 }

Thank you for your help! [1]: http://docs.unity3d.com/Documentation/Manual/UnityWebPlayerandbrowsercommunication.html

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
avatar image
0

Answer by Minizinger · Oct 10, 2013 at 11:54 AM

I don't know how to use yield in this way. In my code I'm just using something like this:

 using UnityEngine;
 using System.Collections;
 
 public class sas : MonoBehaviour {
     
     bool loading = true;
     GameObject SomeObject;
     
     void Update () {
         if(SomeObject == null){
             SomeObject = GameObject.Find("Name of this object");
             loading = true;
         }
         else
             loading = false;
     }
 }

hope it will help.

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

Follow this Question

Answers Answers and Comments

18 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Resources.Load Instantiate Yield problems 1 Answer

Respawn after delay 3 Answers

Instantiating many objects during update lags 1 Answer

Respawn after delay 3 Answers

Coroutines insider another coroutine. 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