Forum rules - please read before posting.

[Minor issue] LoadingScene: [Timer] loading progress bar disappears before showing up at 100%

edited July 2019 in Technical Q&A

Hi there!

I have a BootScene, a LoadingScene and Scene01

From BootScene I'm transitioning to Scene01, so the LoadingScene pops up and the corresponding "Loading" menu gets shown. I read the tutorials and I believe it's been set up correctly.

Everything is fine, asynchronous loading of Scene01 happens while LoadingScene is showing a Timer element with size set to Manual, that scales up from 0 to 100.

Fact is, I debugged it and it correctly loads up to 1 (multiplied 100), but never actually reaches 1. As soon as the scene is loaded it switches back to 0.

So, I put a condition that the progress only updates if a bigger number is passed, and if the current progress is greater than 0 and we're fading out, I'm forcing a value of 100;

Yet, in the console it works perfectly (reaches and stays 100 until the loading scene gets discarded and fades out), but as soon as the variable loadingProgress gets to 100, the Timer/progressBar disappears.

It's a minor issue, but I'd love to have the bar showing at 100% while it fades out.

Am I missing something? Does the bar disappear because of layout reasons (too big?)
I can't explain it.

Is there a way to have the value updated more frequently (I believe there's a way to create a coroutine in AC, but I guess it's a Unity issue. I can "fake" the smoothness in other ways)

Here's the full code put inside a generic GameObject inside the LoadingScene:

Could you please help me find out why the variable works and the Timer doesn't ?

using System;
using System.Collections;
using System.Collections.Generic;
using AC;
using UnityEngine;
using UnityEngine.Experimental.PlayerLoop;

public class LoadingSceneManager : MonoBehaviour
{
    public string loadingMenuName;
    public string progressBarName;

    [SerializeField] protected float loadingProgress;
    protected const float TOLERANCE = 0.01f;

    protected Menu cachedMenu;
    protected MenuTimer cachedProgressBar;

    public LoadingSceneManager(float loadingProgress)
    {
        LoadingProgress = 0f;
    }

    private void Awake()
    {
        cachedMenu = PlayerMenus.GetMenuWithName("Loading");
        cachedProgressBar = PlayerMenus.GetElementWithName(loadingMenuName, progressBarName) as MenuTimer;
    }

    public float LoadingProgress
    {
        get => loadingProgress;
        set
        {
            if (loadingProgress > 0f && Math.Abs(value) < TOLERANCE || cachedMenu.IsFadingOut())
                SetLoadingProgress(100f);
            else if (loadingProgress < value)
                SetLoadingProgress(value);
        }
    }

    protected virtual void SetLoadingProgress(float value)
    {
        loadingProgress = value;
        cachedProgressBar.SetSize(new Vector2(value, cachedProgressBar.GetSize().y));
        AC.KickStarter.playerMenus.UpdateLoadingMenus();
    }

    private void FixedUpdate()
    {
        LoadingProgress = KickStarter.sceneChanger.GetLoadingProgress() * 100f;
        Debug.Log(loadingProgress);
    }
}

Comments

  • edited July 2019

    I will need to attempt a recreation, first. Have you set a non-zero Delay before and after (s) value in the "Scene loading" settings?

    The value returned by GetLoadingProgress is updated every frame (and used to update the Timer every frame as well), so the value itself will be down to Unity. To fake smoothness, you'd have to create a non-AC-linked UI Slider that lerps it's own value to GetLoadingProgress. However, I shall consider adding an auto-smoothing option to the Timer element's properties.

  • Yup, that's exactly what I did, I simply lerped to a target value to fake smoothness.
    I'm now using TextMeshPro (would be great if AC used it natively).

    Iirc, I tried both ways. On the console the script logs the correct values, but it's like MenuTimer doesn't get updated to reflect that.

  • A fix for the timer, and a smoothing option, will be available in the next release.

    I'm now using TextMeshPro (would be great if AC used it natively).

    It is - enter "TextMeshProIsPresent" as a Scripting Define Symbol in your Player settings, and the Menu system will refer to TextMeshProUGUI components instead of Text.

    See the Manual's "Supported third-party assets" chapter for more on this topic.

  • Hi Chris,

    I have that define symbol, I read the docs, yet, using AC menu system (so, not uGui), text and effects really don't look like those of TMPro. But yes, choosing uGui as a menu system shows up fields referring to TMPro. I was talking about the default AC menu System to use SDF fonts.

  • Thanks for the clarification. TMPro support is limited to Unity UI.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.