Best practiecs to change variables mid-dialogue.

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
bluespheal
Posts: 3
Joined: Tue Jul 01, 2025 8:23 pm

Best practiecs to change variables mid-dialogue.

Post by bluespheal »

Hi, after going through the documentation, I can't seem to find a simple or straightforward way to accomplish this, that or my constant browsing is confusing me, so I figured it would be easier to ask here, also, I think I found a post trying to accomplish something similar, but it's around 6 years old, so I would like to know if a newer, more convenient solution is available now.

So, I'd want to be able to change a variable during a conversation, or to accomplish the same effect, run an arbitrary method mid-sentence while the type-writer effect is printing characters.

For example:

Variables: Pitch, default value = 0

Dialogue Text: Hello friend, ["Pitch" = 1 ] turns out I'm really happy!, ["Pitch" = 0 ] how about you?

Here I'd want to change the Variable Pitch mid-dialogue so that another piece of code elsewhere could adjust the actual pitch of the sound being played, it doesn't necessarily need to change the Variable as I could do that directly via a custom function, but I'm also unsure if calling an arbitrary function like that is possible.

I've looked into sequence messages and something like "SetVariable(Pitch, 1)@Message (happy);" could work, but again, I am unsure on how to call said message from the Dialogue Text.

Any other approach or suggestions are welcomed, I feel I'm over-complicating things or missing something crucial here.
User avatar
Tony Li
Posts: 23376
Joined: Thu Jul 18, 2013 1:27 pm

Re: Best practiecs to change variables mid-dialogue.

Post by Tony Li »

Hi,

There's not a single, simple solution for that. Any solution will require a bit of code.

The easiest way by far is to use Text Animator and add an event trigger in your text..

If you can't use Text Animator, then two alternate solutions are:

1. Make a subclass of TextMeshProTypewriterEffect (if you're using TMPro) or UnityUITypewriterEffect (if you're using UI Text) and override the Play() coroutine to handle special [Pitch=#] tags.

2. Or use an OnConversationLine(Subtitle) method to extract the [Pitch=#] tags from the text, determine the time mark at which they'd be typed, and add them to the subtitle's sequence as custom sequencer commands.
Post Reply