Hiding text/choosing which text to show in unity

i'm making a dialogue system that reads from a text file with a portrait that changes expressions depending on the context. I'm thinking of putting in a "cue" in the text file to determine which expression to show on the screen. Like #1 for default expressions, 2 for happy, etc. But the problem is the cues will show up on the dialogue box as well.

So, is there a specific code to hide texts specifically in unity like how "\n" is not shown in other languages? Because my other solution to this is making two separate files and scripts for the dialogue and expression cues which will probably add confusion and more problems in the future.

• Have you considered using regex to filter your strings at runtime? – Weckar E. Nov 30 '20 at 9:09

As far as I know there is nothing like that. But I also don't see why anyone would need a feature like that, because there is no way in Unity to put text from a file directly into a UI text element. There is always at least one step in between where you read the content of the text file into a string variable. And this is where I would approach this problem.

For example, you could say that when a line in your text file begins with { (or some other character which is unlikely to show up in regular dialogue text) then this line is the facial expression. When the line begins with anything else, it's a line of dialogue.

But maybe you want to add more kinds of "stage directions" later. Audio, effects, and so on. And sooner or later you run out of symbols. So you might want to use just one symbol followed by a word which describes what that symbol means. And if you go so far, then the actual text might not look that special anymore, so it should also be notated by a word. So you might end up with a file format like this:

{ "character": "bob" },
{ "emotion": "happy" },

Wait a minute... that is JSON! A standardized format for hierarchical key/value data. One which Unity can actually parse out of the box. So you don't even need to write your own file parser. You just need to create a plain old C# class with all the fields which you can have in a line of dialogue and then use the method JsonUtility.FromJson to take a text string and create and instance of that class.