Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

SuperTextMesh.Read() not work in some cases:

A topic by Wanwu created Jul 01, 2022 Views: 261 Replies: 10
Viewing posts 1 to 2
(3 edits)

Hi I found that Read function doesn't work in some cases, I'm not sure if it's a bug.

1. if Read Function is in Awake or Start

2. if gameobject is disabled and execute following code

         superTextMesh.gameObject.SetActive(true);

        superTextMesh.Read();


Read() seems to be blocked by some other code.



Developer

Hmm, I'll be able to take a look into this shortly!

For now, I'm curious what the state of autoRead is for this, and if it could be causing a conflict somehow. Do you get the results you want if autoRead is left true, and Read() isn't called? (The behaviour you're trying to do should work regardless, I'm just trying to hunt down the cause and can't open my dev environment at the moment)

(5 edits)

I ran some more tests about Read() (auto read is false, super text mesh is disabled at the beginning):

 public IEnumerator TestCode1()

    {

        superTextMesh.gameObject.SetActive(true);

        superTextMesh.Read();

        Debug.Log(superTextMesh.reading);  //true

        yield return null;

        Debug.Log(superTextMesh.reading);  //false(Read() is blocked there)

        yield return null;

        Debug.Log(superTextMesh.reading);  //false

    }

        public IEnumerator TestCode2()

    {

        superTextMesh.gameObject.SetActive(true);

        yield return null;

        superTextMesh.Read();

        Debug.Log(superTextMesh.reading);  //true

        yield return null;

        Debug.Log(superTextMesh.reading);  //false(Read() is blocked there)

        yield return null;

        Debug.Log(superTextMesh.reading);//false

    }

    public IEnumerator TestCode3() //Read() works in this case

    {

        superTextMesh.gameObject.SetActive(true);

        yield return null;

        yield return null;

        superTextMesh.Read();

        Debug.Log(superTextMesh.reading); //true

        yield return null;

        Debug.Log(superTextMesh.reading); //true(Read() keep working later)

    }

I needed to wait at least two frames after super text mesh was activated to execute Read(), otherwise the code would not work.

(4 edits)

  Here is another test about auto Read. Auto read works normal, but sometimes I need to set the start position.here is a test about currentReadTime(set Remember Read Position to true or false will get same result)

    public IEnumerator TestCode4()

    {

        superTextMesh.gameObject.SetActive(true);

        superTextMesh.currentReadTime = 10;// not work, Read position not change

    }

    public IEnumerator TestCode5()

    {

        superTextMesh.gameObject.SetActive(true);

 yield return null;

        //superTextMesh.currentReadTime = 20;// it works, read Position change to 20

    }


set currentReadTime immediately after gameobject set active will not change the read position. The same problem happens on SkipToEnd() too.

Developer

In SuperTextMesh.cs, please comment out line 1672! So... please turn this...

}else{
                StopReadRoutine();
                //Debug.Log("Not autoreading");
                SetMesh(0f); //show nothing
            }

into this

}else{
                //StopReadRoutine();
                //Debug.Log("Not autoreading");
                SetMesh(0f); //show nothing
            }

I think my original intent with this code was... If STM has a read delay > 0, but is not set to autoread, stop the read coroutine and set the mesh to be empty. But this stop coroutine call would halt a manual Read() too. I think removing this line should work, so please let me know if it works for you!

(3 edits)

Sorry, but it still doesn't work. I still need wait 2 frame after super text mesh activates to use Read(), otherwise, when I use Read() the entire text will show immediately without reading process.

And if I set auto read to true, skip to end  and currentReadTime will still not work if super text mesh is just active. (I need use yield return null to wait one frame after super text mesh is active).

Developer

Hmm... what version of Unity are you using? and are you using STM with Unity UI, or without? The behaviour upon start is a bit different between the two, so maybe that's why I got different results than you did

(4 edits)

Unity 2020.3.33f1c2 and I used Unity UI for test(stm is inside Canvas). I have tried 3D stm, and the result is same.

(2 edits)

There are the setting of stm and  the code I used for my tests, maybe this information will be useful to you.

using System.Collections;

using UnityEngine;

public class Test : MonoBehaviour

{

    public SuperTextMesh superTextMesh;

    private void Awake()

    {

        superTextMesh.gameObject.SetActive(false);//the superTextMesh is hide when game is start.

        superTextMesh.readDelay = 0.01f;//read delay >0

        superTextMesh.autoRead = false; //auto read set false, I will call auto read later

    }

    //add it to buttons

    public void AddToButton1()

    {

        StartCoroutine(TestCode1());

    } public void AddToButton2()

    {

        StartCoroutine(TestCode2());

    } public void AddToButton3()

    {

        StartCoroutine(TestCode3());

    }

    //set stm gameobject active and call read immediately.

    public IEnumerator TestCode1()

    {

        superTextMesh.gameObject.SetActive(true);

        superTextMesh.Read();

        Debug.Log(superTextMesh.reading);//true

        yield return null;

        Debug.Log(superTextMesh.reading);//false

        yield return null;

        Debug.Log(superTextMesh.reading);//false

        yield return null;

        Debug.Log(superTextMesh.reading);//false

    }

    //set stm gameobject active and call read after one frame.

    public IEnumerator TestCode2()

    {

        superTextMesh.gameObject.SetActive(true);

        yield return null;

        superTextMesh.Read();

        Debug.Log(superTextMesh.reading);//false

        yield return null;

        Debug.Log(superTextMesh.reading);//false

        yield return null;

        Debug.Log(superTextMesh.reading);//false

    }

    //set stm gameobject active and call read after two frame.

    public IEnumerator TestCode3()

    {

        superTextMesh.gameObject.SetActive(true); 

        yield return null;

        yield return null;

        superTextMesh.Read();

        Debug.Log(superTextMesh.reading);//false

        yield return null;

        Debug.Log(superTextMesh.reading);//false

    }

}

Developer (1 edit)

Ok, I think I've fixed it! Please send me an email through my website so I can send you an updated version of SuperTextMesh.cs!

I just emailed you and thank you so much for your help.