Skip to main content

On Sale: GamesAssetsToolsTabletopComics
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 24 days ago Views: 145 Replies: 13
Viewing posts 1 to 10
(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:

Developer

Here's the code, it's quite basic and only copies over one value to the LayoutElement, but could be modified to nab other values, too: https://pastebin.com/XbvqHeCC (I don't want to do it myself because it's the long weekend - maybe tuesday!)

Can the TMP object be moved elsewhere? Curious if it's controlling position at all.


Will think more on this over the weekend, but I'd really just like to figure out... what is trying to make this move back to the origin anyway? Could it be a setting for subtitle location in AC or something...?

Hi Kai - thanks, flip, sorry to interrupt your long weekend. I struggled with the script, some error about a layout element was not defined if I remember correctly. Would love to get your input on Tuesday please, thank you.

I've also asked Chris, creator of Adventure Creator, if he has any further ideas and passed on the info you've provided. I'd also love to get this working well! Been a challenge thus far but would be great if it worked well, really hoping so. 馃檹

I have a Content Size Fitter on both the 'Panel_TextBG' and the 'TextBoxContainer'. I think TextBoxContainer constrains the max horizontal width of the subtitles and pushes text down vertically when it reaches the edge of it, and then the child one Panel_TextBG trims the background box to whatever text is passed into it:



Developer

Yeah, I think the problem may be that it's two content size fitters immediately inside of one another (but I'd expect this to effect size, not position... so might be the wrong path to look down?) ...without a layout group or layoutelement to help decide what controls what.


The way the code I sent works is... you reference an STM component, then you reference a LayoutElement component, and the height value from STM is sent directly to the layoutElement's "preferredHeight" field. (Make sure preferred height is enabled on the layoutelement or this does nothing) The LayoutElement is intended to be the parent object of the one STM is on, in this example. I'm catching this before bed, could add the other fields besides height for you tomorrow.


Hm, you said before that TextBoxContainer also has a vertical layout group already, but it *might* work here with using a layoutelement and setting values directly from the child STM object. I'm still not completely convinced this is the error though since it's *always* just returning to the same point before being corrected what I can assume is a layout refresh... so even if we fix the layout refresh, something could still be responsible for the move.

It might also be worth seeing if reducing nesting would help - could txtSubtitles be made a sibling of Panel_TextBG instead of a child? If you go into STM's sample scenes, there's a "MatchRect" script that will let one rectTransform fit to STM with various settings, regardless of parenting. I forgot to mention this before, this is probably a more direct and thorough fix than piggybacking off LayoutElement... probably!


So please give that last one a shot! That might be better since you're trying to size a box based on text size, anyway!

(1 edit)

Hey, thanks so much for these suggestions.
After a lot of fiddling, it seems like the conflict is maybe the nesting, or rather having 2 'Vertical Layout Group' components on 2 different nested objects. If I disable one of the Vertical Layout Groups, I don't get the issue. I tried replacing one with a Horizontal Layout Group, but no luck.

I did try a Layout Element - it gets rid of the recording position glitch, but I couldn't seem to get the wrapping of the text right (the text ran off the screen), or the background box just didn't shrink to conform to the text - this kind of double nested setup I have seems to be the only way I can find thus far to get the text to wrap correctly to a max shape. 

I also tried your script, and just couldn't figure out how to get it to work with the Adventure Creator Subtitles menu I'm afraid -  maybe the ACWiki script was clashing with it, not quite sure. If you have more suggestions for how to set that up correctly, I'd love to please try! 馃檹

Also some (maybe) useful info - the double vertical group issue position recording glitch only happens when I have the Super Text Mesh  component enabled. If I disable it and enable Text Mesh Pro on the object, the double nesting doesn't seem to be an issue with recording. Hopefully helps with troubleshooting. 

The script you sent - what object should I put that on? I didn't seem to get fields in the inspector when I attached it to eg the STM object, I'm not a code expert by any means, but it looks like I should have got some public fields to drag objects into? Even a more basic question, but should it be a CSharp script or a Mono?

Developer

Layout issues like that can even stump experts, so it's a bit tough to debug this all without doing it myself... sorry for that!


For the MatchRect script, to be a bit more clear about how it works... Place it on the object you want to resize to match the text's bounds (so in your case, the background) and then in the inspector, you need to drag in the gameObject that has SuperTextMesh on it from the hierarchy into the "stm" field. (Ideally the objects are siblings in this case). 


But it sounds like Adventure creator may be trying to resize the box itself, so this might be the wrong approach... (Sorry it's been a very long time since I've had AC's code in front of me, so I need to guess... If AC is trying to set the box size itself, you need to remove the ContentSizeFitter from STM, and set the anchor presets on its recttransform to stretch. (So it'll match whatever AC is actually resizing) So in this instance, instead of the text controlling the box size, the text is fitting in the box size. Not entirely sure this is the case here though.



I'm actually not too sure what to make of that maybe useful info immediately... does it *only* happen when recording? Could the STM object have anything else on it causing an issue in this instance?


For the script I sent, forget about it for now because it was incomplete and I wanted to expand on it, I don't think it would have changed much in its current state. I also think the MatchRect script might be a more direct fix for this issue. But yes, it has public fields, one for an STM component, and one for a LayoutElement... it's meant to send values generated by STM straight to the LayoutElement, which could be a parent object in your case. It's C# code, by the way!


If I'm not able to solve it like this, I might ask you to sent over a scene for me to edit, I feel like it might just be one thing out of place, and the fastest way to know is by just pushing all the buttons, haha. I'd really like to isolate the issue because it's still not completely clear if it's an issue with STM, AC, or Unity Layouts!

Hey Kai - thanks man. Also been watching the YT videos you have linked on the Asset store page, and I wondered if I might try forego a lot of Canvas UI's stuff and try and get STM to do a lot of the work, since you seem to have 'Vertical Limit' build in to STM and I'd generally want to try and set the text at a predefined point above each character's head using AC's setting for each character, and then when the text goes over a certain horizontal limit, it expands vertically, preferably up. BUT, there's also an AC setting to always keep text inside the screen at all times, so one RectTransform object is requited I believe. Is there a way to automatically generate a kind of semi-transparent coloured background to the text, to simulate a text box? Then I maybe wouldn't need all the other nesting objects.

Yes, only seems to happen when recording with Unity's Recorder. At 60fps it's almost imperceptible but still noticeable.

Anyways, instead of me asking all these questions, I think what'd be best (like you suggest) is if I ZIP my project and send it to you to have a squizz at if that's ok. Will email you a GDrive link shortly.

Developer

If you can let STM do most of the work, see if that works for you! The AutoWrap feature sounds like what you're after, with VerticalLimit being its vertical counterpart. (On UI text, these values are controlled by the size of the recttransform, by the way!!! Unless"ui wrap" and "ui limit" are disabled.) 


The STMMatchRect code in my sample scenes really sounds like what you're looking for - it just takes an existing rectTransform which you can change the appearance of, and resizes it based on text size. (With options for which bounds it's copying.) So please check out the sample scene for that.


What is your monitor's refresh rate? If it's higher than 60, that means the issue shouldn't be something delta-related, so that helps narrow it down at least. (Thinking it's happening on a per-frame basis, rather than a per-time basis) 


Got your zip, will check it out shortly!