Can't tell when VaM finishes loading

vamX

Well-known member
Featured Contributor
Messages
173
Reactions
632
Points
93
Website
www.patreon.com
Patreon
vamX
This is a bit more obscure, but it's something I'm constantly having to work around. I'm loading assetbundles, clothes, audio, etc. from script, but SuperController.singleton.isLoading is not a reliable method of determining if things are loading. I am doing things like the code shown below in the hopes of finding the right finished loading time, but it's a bit hackey and I'm not sure if it will work in all situations. It would be great if there were a function to call that accurately stated whether or not everything that was requested to be load, was finished loading.

Alternatively if yield return could work in all situations that would be an alternative.

For example this works:
yield return SuperController.singleton.AddAtomByType();
but loading presets, clothes, etc. we can't tell when they (and the associated textures) are done loading.

//my hack
//hopefully enough delay to finish loading
for (int i = 0; i < 30; i++)
{
yield return new WaitForEndOfFrame();
while (SuperController.singleton.isLoading)
{
yield return new WaitForSeconds(0.1f);
}
}
 
I suggest using the callback system.

Code:
protected void OnSceneLoaded() {
   // ... your code
}

protected void OnEnable() {
    SuperController.singleton.onSceneLoadedHandlers += OnSceneLoaded;
}

protected void OnDisable() {
    SuperController.singleton.onSceneLoadedHandlers -= OnSceneLoaded;
}

But as you mention, many things in VaM are loaded asynchronously, like Unity assets, images, audio, etc. But the scene load function in SuperController should already be taking that into account. It waits for async loads to complete that were registered during the load process before calling the onSceneLoadedHandlers.

But you also mention presets, etc. These can trigger the loading icon, but there is currently no event system to notify when load started and completed. In some cases, many events could be triggered as the loading may not be contiguous. The only thing I see possible for you today is to check if the loadingIcon is active or not to determine if something is being loaded:

Code:
protected void Update() {
    if (SuperController.loadingIcon.gameObject.activeSelf) {
        // something is loading (includes images, hair/clothing/skins, audio, etc.)
    } else {
        // nothing is currently loading right now
    }

}

I could probably add events for when load has started and ended, but again you should be prepared for non-contiguous events in some cases.
 
I'm usually going for something like this, hasn't failed me yet. Essentially pretending we are loading for one more frame after VaM tells you it has finished and then doing whatever refresh you needed after loading. Using variants of this in many of my plugins.
C#:
bool myWasLoading = true;
bool myNeedInit = true;

public override void Init()
{
    myWasLoading = true;
    myNeedInit = true;

    // ...
}

private void ActualInit()
{
    // ...
    
    myNeedInit = false;
}

private void Update()
{
    bool isLoading = SuperController.singleton.isLoading;
    bool isOrWasLoading = isLoading || myWasLoading;
    myWasLoading = isLoading;
    if (isOrWasLoading)
        myNeedInit = true;
    else if (myNeedInit)
        ActualInit();
        
    // ...
}
 
sorry, i'm a newbier, somebody show me how to download VAM ????
It's generally considered to be a bad idea to revive a three year old discssion with a question about a totally different topic.

Anyway, download info are here:

To activate VaM, you need to subscribe to MeshedVR on Patreon, where you get a key. There are different Tiers to choose from, these are explained on the following page. However, since you only need to subscribe for a single month, there isn't really any reason to not get "Creator" tier right away. You may have to re-subscribe later, if you want a version update, but you can keep using the version you have forever.
 
It's generally considered to be a bad idea to revive a three year old discssion with a question about a totally different topic.

Anyway, download info are here:

To activate VaM, you need to subscribe to MeshedVR on Patreon, where you get a key. There are different Tiers to choose from, these are explained on the following page. However, since you only need to subscribe for a single month, there isn't really any reason to not get "Creator" tier right away. You may have to re-subscribe later, if you want a version update, but you can keep using the version you have forever.
Thank you so much!!!!
 
OnSceneLoaded
I'm usually going for something like this, hasn't failed me yet. Essentially pretending we are loading for one more frame after VaM tells you it has finished and then doing whatever refresh you needed after loading. Using variants of this in many of my plugins.
C#:
bool myWasLoading = true;
bool myNeedInit = true;

public override void Init()
{
    myWasLoading = true;
    myNeedInit = true;

    // ...
}

private void ActualInit()
{
    // ...
   
    myNeedInit = false;
}

private void Update()
{
    bool isLoading = SuperController.singleton.isLoading;
    bool isOrWasLoading = isLoading || myWasLoading;
    myWasLoading = isLoading;
    if (isOrWasLoading)
        myNeedInit = true;
    else if (myNeedInit)
        ActualInit();
       
    // ...
}
(y)Very useful,you saved my day
 
Back
Top Bottom