Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

Text stops reading after calling Read() when instantiated

A topic by Max Cordeiro created Dec 31, 2021 Views: 121 Replies: 3
Viewing posts 1 to 2

I've run into an issue where text will start to read (draws the first character) and then rebuilds, stops, and clears the drawn text. I have autoRead turned off and I'm calling Read() after instantiating the message object. It looks like it's being rebuilt a few times in SuperTextMesh.cs's Update() which causes it to stop reading. Is it not possible to manually call Read() so soon after instantiating without autoRead? This is the Update() code I'm using to instantiate my message object:

    public void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            msg = UIHandler.instance.LoadMenu(MenuConstants.UIMESSAGE).GetComponent<UIMessage>();
            msg.AddMessage("A wild monster appeared!");
            msg.textMessage.Read();
        }
    }

I can provide screenshots of my prefab setup and more code if needed.

Developer

Hm, if it's STM's Update() cycle causing the rebuild, is it one of the two "validateAppearance" boolean calls? The only other Rebuild() call in Update() is invoked when the screen size changes. All the Rebuild() methods in Update() only happen when using the Unity editor, to make it easier to preview text.

I could change those Rebuild methods so that they still respect autoRead, but if a mesh is in the middle of reading, it will Rebuild from the same point. But the intention for them is that when editing the Unity editor, changing the inspector forces text to rebuild. So I don't think I should make that a change...

I hope I'm understanding the problem correctly though! I'm not sure what's causing those Rebuild() methods to go off, exactly. Are you resizing the window in Unity or editing STM's inspector?

I thought it had to do with validateAppearance but I commented those lines out and also ran a build (since it's inside an editor check) but it still gets cleared. I actually dug a little deeper and found out it's coming from Start()'s StartCoroutine(WaitFrameThenRebuild(autoRead))! I commented it and it reads without stopping now. I had a lot of Debug.Log's to go through and I must have gone to the wrong one and assumed it was coming from Update(). Sorry about the confusion.

Developer (1 edit)

Ahh, ok... Yeah hm WaitFrameThenRebuild() was initially added to solve a problem where STM wouldn't Rebuild upon being loaded into a new scene... but the call for UI text under Start()... I wish I commented *why* I set it up like that. My best guess is that I did it to get around an issue with Unity UI refusing to update it's layout, despite calling every possible way to refresh it. If that line is changed to just Rebuild(autoRead) I wonder if that would fix it, without causing the previous UI layout issues to come back...? I might have fixed the aforementioned layout issues in a previous build, but a new Unity UI layout issue always seem to crop up upon fixing an old one.