Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

Thank you for your reply.

I call it on Awake, but I use call coroutine, and setting text is called a few frames later from Awake().

As I said, I find all SuperTextMeshes in my scenes and set texts on launching.

I changed it to an async function and it worked.

So the problem is solved now but I'm afraid that the problem will occur again.

Here is my sample code (Some part of the code is omitted, so it doesn't work).

public class MessageDatabase : SingletonScriptableObject<MessageDatabase> {
    public void ApplyAllUIText( Scene scene )
    {
    GameObject[] objs = scene.GetRootGameObjects();
    foreach (var obj in objs) {
    ApplyAllUIText( obj );
    }
    }
    
    public void ApplyAllUIText(GameObject obj)
    {
        Text text = obj.GetComponent<Text>();
    if( text != null )
    {
            InterpretText( ref text );
    }
    
        var tmp_text = obj.GetComponent<TextMeshProUGUI>();
    if( tmp_text != null )
    {
            InterpretText( ref tmp_text );
    }
        
        var stm_text = obj.GetComponent<SuperTextMesh>();
    if( stm_text != null )
    {
            InterpretText( ref stm_text );
    }
    
    var trans = obj.transform;
        for( var i = 0; i < trans.childCount; ++i ) {
    Transform t = trans.GetChild( i );
    ApplyAllUIText( t.gameObject );
        }
    }
    
    public void InterpretText( ref Text t )
    {
        if( t.text.StartsWith( "$$" ) )
        {
            string key = t.text.Substring(2);
            t.text = GetText( key );
        }
    }
    public string GetText(string key)
    {
        ...
    }
}