Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

[Solved] Text disappearing on LoadSceneAsync() single

A topic by apocriva created Oct 24, 2017 Views: 652 Replies: 9
Viewing posts 1 to 8
(1 edit)

When loading a scene via SceneManager.LoadSceneAsync(scene, LoadSceneMode.Single), all super text mesh text disappears. Works fine when loading Additive, or non-async.

Tested in Unity 2017.1.0p5 64 / STM 1.6.2.

I've posted a minimal repro case project for this issue:

https://drive.google.com/file/d/0ByJ3vw9WEdpZdndLT2RXUnZ2VWs/view?usp=sharing

Developer

Thanks for the repro! I've been meaning to look into this Async loading issue for ages, but never got a repro for it.

The current solution is calling SuperTextMesh.RebuildAll() when the scene is done loading, but now with this repro I'll hopefully find a real solution shortly. Thanks!

Developer

First thing I noticed was that the text in the new scene is there for a single frame before disappearing. Also, Rebuild() is being called, and I set up a debug to check this. If I tell a mesh to not Rebuild() under Async single loading, the 1-frame flash doesn't happen. Even more interesting, this appears to only be effecting UI text! I added a non-Unity UI Super Text Mesh object to the scene, and it survived the load just fine.

I do notice that with debug mode enabled, the new scene's STM object doesn't appear to have an internal material. This material is still there when I switch the load mode to additive, so this has the be the cause of the problem.

It looks like if I tell STM to wait a frame before Rebuild() is called, it seems to work fine? As far as I can tell, it's not even flashing for the one frame it's not supposed to be there for. Give this a shot and lemme know what you think, and let me know if you see it blink for one frame. If it does, Rebuild() will just have to be called again, right before that "yield return null" line.


On line 821 of SuperTextMesh.cs, replace everything in the #if statement with these functions:


void OnSceneLoaded(Scene scene, LoadSceneMode loadSceneMode){
    if(this != null){
        if(loadSceneMode == LoadSceneMode.Single){
            StartCoroutine(WaitFrameThenRebuild());
        }else{
            Rebuild(autoRead);
        }
    }
}
IEnumerator WaitFrameThenRebuild(){
    yield return null;
    Rebuild(autoRead);
}

Works like a charm, thanks for the quick turnaround. :)

Developer

Sweet! I'll implement this and upload a new version shortly. Thank you so much for the repro!

(3 edits)

This topic helped me to solve my problem. In my game there is one big big world, with smallest scene blocks that will be loads async by reach. So, when I create STM (UI) with reading, and hero going in area with new scene and begin async loading - then this STM reloaded and begin "read" from the start. I have removed  all code from "OnSceneLoaded" and all going well (STM don't disappear and nothing else bad, Unity 2018.2.0f2). In all my cases of the game this is enough.

PS. At first, I tried disable "AutoRead" and run "Read" once when I want, but method "Read" don't work.

Developer

Oh heck, nice catch. I think I get what you mean... another scene is loading, and this calls the OnSceneLoaded() delegate event in Super Text Mesh, which then tells super text mesh to Rebuild, regardless of if it was actually in that new scene or not!


Could you revert your code to what it was before, and change the IEnumerator "WaitFrameThenRebuild" to this:


IEnumerator WaitFrameThenRebuild(){
        yield return null;
        Rebuild(currentReadTime, autoRead);
    }

The mesh will still rebuild itself, but it should remember where it last left off with this method. Please tell me if this fixes your issue!

(1 edit)

Super. It fixed my problem.

Developer

Awesome, already published this update!