Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

nukenin-waken

2
Posts
1
Topics
A member registered Feb 13, 2021

Creator of

Recent community posts

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)
    {
        ...
    }
}
(2 edits)

Hello, KaiClavier

I purchased Super Text Mesh and I have trouble.

When I try to set text, sometimes the following error occurs.

ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
System.ThrowHelper.ThrowArgumentOutOfRangeException (System.ExceptionArgument argument, System.ExceptionResource resource) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.ThrowHelper.ThrowArgumentOutOfRangeException () (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Collections.Generic.List`1[T].get_Item (System.Int32 index) (at <695d1cc93cca45069c528c15c9fdd749>:0)
UnityEngine.UI.Collections.IndexedSet`1[T].get_Item (System.Int32 index) (at /Applications/2020.3.8f1/Unity.app/Contents/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/UI/Core/SpecializedCollections/IndexedSet.cs:113)
UnityEngine.UI.CanvasUpdateRegistry.PerformUpdate () (at /Applications/2020.3.8f1/Unity.app/Contents/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/UI/Core/CanvasUpdateRegistry.cs:221)
UnityEngine.Canvas.SendWillRenderCanvases () (at /Users/bokken/buildslave/unity/build/Modules/UI/ScriptBindings/UICanvas.bindings.cs:83)
UnityEngine.Canvas.ForceUpdateCanvases () (at /Users/bokken/buildslave/unity/build/Modules/UI/ScriptBindings/UICanvas.bindings.cs:71)
SuperTextMesh.Rebuild (System.Single startTime, System.Boolean readAutomatically, System.Boolean executeEvents) (at Assets/Clavian/SuperTextMesh/Scripts/SuperTextMesh.cs:1480)
SuperTextMesh.Rebuild (System.Single startTime, System.Boolean readAutomatically) (at Assets/Clavian/SuperTextMesh/Scripts/SuperTextMesh.cs:1465)
SuperTextMesh.Rebuild () (at Assets/Clavian/SuperTextMesh/Scripts/SuperTextMesh.cs:1455)
SuperTextMesh.set_text (System.String value) (at Assets/Clavian/SuperTextMesh/Scripts/SuperTextMesh.cs:763)

It happens sometimes, not always.

I don't know why it happens.

In my project, I try to find all SuperTextMeshes in my scenes and set texts on launching.

Is it possible that it makes the problem?

Could you give me some advice?

Unity version: 2020.3.8f1

Text Mesh Pro version: version 1.11.2