Author Topic: UIProgressBar AsyncOperation issues  (Read 8495 times)

singh029

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 28
    • View Profile
UIProgressBar AsyncOperation issues
« on: March 14, 2014, 01:20:36 AM »
Hi! so im having some issues getting a progress bar to load.. :'(
I have this script attached to main camera. The UIProgressBar loadingAnim is inactive until the game mode button is pressed in another script and launches the coroutine.

  1. public class LoadingUI : MonoBehaviour {
  2.  
  3.         private UIProgressBar loadingAnim;
  4.  
  5.         public AsyncOperation async = null;
  6.  
  7.         // Use this for initialization
  8.         void Start ()
  9.         {
  10.                 loadingAnim = GameObject.Find("Main Camera Menu").GetComponent<UIProgressBar>();
  11.         }
  12.        
  13.         // Update is called once per frame
  14.         void Update ()
  15.         {
  16.                 if(loadingAnim != null)
  17.                 {
  18.                         loadingAnim.value = async.progress;
  19.                 }
  20.         }
  21.  
  22.         public IEnumerator LoadGameMode() {
  23.                 async = Application.LoadLevelAsync("GamePlay");
  24.                 yield return async;
  25.         }
  26. }
  27.  

Please help!

r.pedra

  • Full Member
  • ***
  • Thank You
  • -Given: 7
  • -Receive: 20
  • Posts: 131
    • View Profile
Re: UIProgressBar AsyncOperation issues
« Reply #1 on: March 14, 2014, 09:06:21 AM »
What is "Main Camera Menu" ? You have an object in your scene called "Main Camera Menu" ?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIProgressBar AsyncOperation issues
« Reply #2 on: March 14, 2014, 10:50:11 AM »
Never use the Find function. Bad, bad bad! Both for performance (EXTREMELY SLOW), and in general (find by name? what if you rename it later without thinking about this code?)

Seeing as nothing in the code you posted actually starts the coroutine, you should reconsider what it is you're doing. Either put the coroutine wherever you're starting the coroutine from, or put this script on the progress bar itself.

You also didn't specify what your issue is. "im having some issues" doesn't explain anything.

singh029

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 28
    • View Profile
Re: UIProgressBar AsyncOperation issues
« Reply #3 on: March 14, 2014, 11:53:33 AM »
Main Camera Menu is the name of the main camera.

LoadingUI script is attached to main camera (Main Camera Menu)
GameMode Panel has a button that calls the coroutine in LoadingUI (deactivates GameMode panel and activates Loading Panel).
Loading Panel has the progress bar. Which is why i need to perform a "find" and check if its null. Otherwise i get a Null Reference.

The issue is that the progress bar just stays at 0. It doesnt load anything.
I just dont know what the structure should be. The panel that has the progress bar is deactivated until the button on another panel is pressed, so i attach the loadingUI script to the main camera so the script stays active to get the loading data.

Thanks again for your help!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIProgressBar AsyncOperation issues
« Reply #4 on: March 14, 2014, 11:55:12 AM »
And where do you actually start the coroutine?

singh029

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 28
    • View Profile
Re: UIProgressBar AsyncOperation issues
« Reply #5 on: March 14, 2014, 02:39:24 PM »
The GameModeUI script is attached to 3 buttons on the GameMode panel.
There are three methods that are in that script (one for each button).
Each of the methods start that coroutine in the LoadingUI script.

DirtyHippy

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 25
    • View Profile
Re: UIProgressBar AsyncOperation issues
« Reply #6 on: March 15, 2014, 01:00:12 AM »
This is likely related to LoadLevelAsync and reporting progress.  There are a ton of topics on this via google where people have similar issues.  I tried to get it to work once, and it reported a progress of 0 during the update method like you have.  It only reported a few ticks (of 0 progress) before the update stopped ticking until the level load was done.  I just removed it and replaced it with a static loading screen.  I haven't tried it for a while - likely I was missing something but many others seem to have this issue.



singh029

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 28
    • View Profile
Re: UIProgressBar AsyncOperation issues
« Reply #7 on: March 15, 2014, 04:44:30 PM »
I just fixed it by putting the load bar outside of the panel, so it can be accessed by both the loading screen panel and gamemode panel. But i also set the loading bar's alpha to 0. and i set it to 1 on Application.isloading.

Its a dumb way of doing things but.... it works.

But i also was having similar issues. it loads to 47,  pauses for a bit and then jumps to 84 and then loads the game.