Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Issue with Adventure Creator and Super Text Mesh

A topic by MIKDOG created 4 days ago Views: 53 Replies: 5
Viewing posts 1 to 5
(1 edit)

Hi - wonder if you could please advise? I'm using this script from the AC Wiki. It mostly works but the issue I'm finding is that the text appears where it shouldn't before it's momentarily teleported to the correct place above a player's head. If I just use Text Mesh pro, this issue doesn't occur, so I suspect it's either something with Super Text Mesh, or the script.

Vid to demonstrate:

Script:

using UnityEngine;
using System.Collections;
public class SuperTextFromACSpeech : MonoBehaviour {
    /*
    This script is to make Super Text Mesh work with Adventure Creator.
    Essentially, it lets AC handle all non-text elements (sound effects, user input),
    while letting STM handle all text-related issues (scrolling speed, animations, colors, etc.)
    Simply put this script on a Super Text ui item in your subtitlesUI adventure creator menu,
    then hide the text item that AC thinks it's referencing (put it offscreen, make it invisible, whatever!).
    AC will play dialogue sounds and handle input as normal,
    but the player will only see the Super Text.
    Script by @johndaguerra.  No credit needed, but I'm cool and it'd make me happy if you followed me on twitter!
    */
    SuperTextMesh supertext;
    AC.Speech speech;
    AC.Dialog dialog;
    void Start () {
        supertext = GetComponent<SuperTextMesh>();
        dialog = FindObjectOfType<AC.Dialog>();
    }
void Update () {
        //If there is dialogue currently being spoken...
        if (dialog.GetLatestSpeech() != null)
        {
            //And you haven't already sampled it...
            if (speech != dialog.GetLatestSpeech())
            {
                //Then set the supertext text to print the dialogue
                speech = dialog.GetLatestSpeech();
                supertext.color = speech.GetColour ();
                supertext.Text = speech.log.fullText;
                //This tells the text to read at regular speeds, in case it was told to speed read
                supertext.RegularRead();
            }
        }
        if (supertext.reading == true)
        {
            if (Input.GetMouseButtonDown(0) || Input.GetKeyDown("space"))
            {
                //If the player clicks or presses space while reading, then speed read
                supertext.SpeedRead();
            }
        }
    }
}

Wonder if any tips to fix it, please? I've tried changing the Canvas Fade to 0, and putting this script higher up in the execution order (and a bunch of other fiddling) but that still doesn't sort it.

I've asked the creator of the script for advice but he says it's so old he wouldn't know whether it's a script issue or an update to Super Text Mesh that'd be causing the glitch.

Developer

Hi! I saw your post with John, let's see what's changed in the last 9 years... (A lot has changed with how Unity UI handles layouts as well)

Immediately seeing, the fading animation starts and then continues as the position corrects itself...

Assuming this is Unity UI... 

1) Try replacing "supertext.Text" with "supertext._text", this is something that I think might have changed in the last 9 years, but I'm not completely sure if it's the issue here. ("Text" I believe used to update text WITHOUT calling Rebuild(), while "text" would, but now "_text" has this function, so the issue could be that Rebuild() is being called twice here and some layout code is getting confused)

2) Try replacing "supertext.RegularRead()" with "supertext.Rebuild(true)", which I think should have the same effect, guaranteeing STM will both rebuild and read at the same time.

3) Try adding supertext.rt.ForceUpdateRectTransforms() after the "RegularRead()" line is called. (Assuming this is on Unity UI) That might force the layout to rebuild if it's a layout issue. You can also try "LayoutRebuilder.ForceRebuildLayoutImmediate()".

4) I'm also guessing at this but... does your STM object have a ContentSizeFitter on it? I've been running into some problems with nested layouts and contentsizefitter in just the last few days actually and wrote myself a rudimentary script to make sure the effects of ContentSizeFitter happen frame 1 with STM, rather than waiting for the layout update. (It just forwards information to a LayoutElement component) So I could try sending over a cleaned up version of the script with this, but with any luck it's one of the first 3 issues.


These are my initial guesses! There's nothing in that code that should be effecting text position besides those 3 things there, so there's a chance it's how AC works now... I can take some guesses at how *that* might work, but I don't use it myself! (I could ask the dev, but I'll try guessing first...)


5) What is the parent object of your STM object? Is it also moving when the text moves? What is making it move? (Thinking maybe AC is trying to use the position of the hidden text object to decide where STM should go, but not sure how it would play initially then decide to move after a few frames...)


Let me know if any of these help!

(2 edits)

Wow, thanks so much! I tried your first suggestion with replacing "supertext.Text" with "supertext._text" and it seems to have done the trick!
Legend! Thank you kindly 馃檹馃檹鉂わ笍
Incidentally, yes, my SubtitlesUI does have quite a few components, the Panel AND the TextBoxContainer have a vertical layout group and a content size fitter, I fiddled until I could get the coloured backing background to fit whatever text was being displayed and this seemed to work.
 

(1 edit)

Not sure if you'd like to update the AC integration script on your side, but for what it's worth this is the adapted script with your suggestion and also this line included, which respects the character's subtitle colour (which I think you suggested adding from some time ago!)

supertext.color = speech.GetColour ();

https://pastebin.com/asr9UKm6

Developer

Perfect! I'm glad it works, I'll just link to your post on the Helper Scripts page!

D'oh, seems I maybe spoke too soon! In the editor, when I play the game, it seems fine, but as soon as I try and record with Unity's recorder, I can see the quick movement before the text gets moved into place. I've tried your other suggestions, and wondered if I could please try that script you suggested that helps with the ContentSizeFitter?

Re your other question,  on the object that has Super Text Mesh on for subtitles, I also have a 'Text Mesh Pro' object on it too that's hidden as it's the only way I can get Adventure Creator's menu to accept the 'linked text' object, as it's looking for a TMP component.

Example of what's happening with recorder: