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.

  • 1
    \$\begingroup\$ Have you considered using regex to filter your strings at runtime? \$\endgroup\$
    – Weckar E.
    Nov 30, 2020 at 9:09

1 Answer 1


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" },
{ "transition": "fade" },
{ "music": "calm.ogg" },
{ "text": "Pleasure to meet you" }

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.

  • \$\begingroup\$ I'm stuck right now so i'll look into this. Thank you very much! But I did made it work by assigning the text file into a string array, then assigning that array into the text element in unity. But now my next problem is that comparing the cue code, which is a string, from the acquired cue string from the text file just wouldn't work even though they're the same string. \$\endgroup\$ Nov 30, 2020 at 10:55
  • \$\begingroup\$ @loverofthefeet If you would show us your parsing code and an example file, then we might be able to find your bug. Perhaps you might want to post this as a new question. \$\endgroup\$
    – Philipp
    Nov 30, 2020 at 10:57
  • \$\begingroup\$ Hi, I made a different post regarding my problem. I should probably just go for the JSON route but I kinda want to know if what i'm currently doing could work. Hopefully my code doesn't put you off but i'd appreciate it if you would check it out. Thank you. \$\endgroup\$ Nov 30, 2020 at 13:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .