Search Unity

loadAsync - Values between 0 and 1 are missing

Discussion in 'Scripting' started by tri-stratos, Jul 21, 2017.

  1. tri-stratos

    tri-stratos

    Joined:
    Jan 29, 2013
    Posts:
    152
    While using the following code under Unity 2017.1.0f3 pro version, to make use of loadAsync to load asynchronously the contents of another scene, the "progress" value, shows me only 0 and 1. Nothing in between!
    At first i though that this was due to running within unity, but that seems also to be the case when using a device as well!
    So is this loadAsync buggy ?
    Please help



    <SCRIPT I USE - START>

    private float progress = 0f;
    private int updateExecuted=0;
    private AsyncOperation operation;

    // Use this for initialization
    void Update()
    {
    if (updateExecuted==0)
    {
    updateExecuted = 1;
    StartCoroutine(LoadAsynchronously(1);
    }
    }

    IEnumerator LoadAsynchronously(int loading_sceneIndex)
    {
    operation = SceneManager.LoadSceneAsync(loading_sceneIndex);
    operation.allowSceneActivation = false;

    while (!operation.isDone)
    {

    progress = Mathf.Round(Mathf.Clamp01(operation.progress / 0.9f));

    Debug.Log("---> " + progress);

    yield return null;

    operation.allowSceneActivation = true;
    }
    }


    <SCRIPT I USE - END>
     
  2. Khazmadu

    Khazmadu

    Joined:
    Jun 24, 2017
    Posts:
    92
    Mathf.Round is rounding the number to the next Integer.
    Use Mathf.Abs instead.
     
  3. tri-stratos

    tri-stratos

    Joined:
    Jan 29, 2013
    Posts:
    152
    @Khazmadu,

    But the issue has nothing to do with Mathf.Abs or Mathf.Round functions.

    Even if one Debug.Log(operation.progress), this still goes from 0 to 0.9 directly instead of reporting the inbetween from 0 to 0.9 values. It reacts as if only the lower and the upper bound values are logged in a way.

    PLEASE anyone help!!
     
  4. tri-stratos

    tri-stratos

    Joined:
    Jan 29, 2013
    Posts:
    152
    I tried everything I could think of but still no intention values.
    Is this buggy in 2017.1.0f3 pro?

    Any help ?
     
  5. tri-stratos

    tri-stratos

    Joined:
    Jan 29, 2013
    Posts:
    152
    It seems impossible here to register values inbetween 0 and 1 at all...

    Any help from anyone regarding this issue ?
     
  6. Khazmadu

    Khazmadu

    Joined:
    Jun 24, 2017
    Posts:
    92
    My Script for loading the scenes is pretty much the same and I'm not getting the problem.
    I have 2017.1.0f3 but not the Pro version.

    Did you try loading a very large scene to make sure that the loading process isn't just to fast to produce anything inbetween?
     
  7. tri-stratos

    tri-stratos

    Joined:
    Jan 29, 2013
    Posts:
    152
    @Khazmadu,

    yes i have tried loading big scenes (~5Mb) and still it only reports 0 and 1, not the inbetween values.

    Could you share your loader just in case a minor but still crucial detail differentiates this weird behaviour ?

    Anyone else have any clue ?
     
  8. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    797
    Are you sure this doesn't have anything to do with rounding the progress value? Have you tried

    Code (CSharp):
    1. Debug.Log(operation.progress);
    to rule it out?