Page 1 of 2

Set a bool value at an specific word within a dialogue node

Posted: Thu Jul 04, 2024 11:20 am
by Jorillan
I´d like to set a bool value at an specific word of the dialogue text of a dialogue node. I have a library of generic expression animations for my characters conversations (angry, exited, Thoughtful, left hand raised, right hand raised,....). I want my characters to change from a standard talking animation to a specific animation depending on the dialogue. It could be that the same animation works for the entire dialogue in a node( in that case I could set the bool normally using the script slot. Variable[X] = true) but sometimes the dialogue in a node involves different emotions or expressions that I would love my characters to reflect. I have set a playmaker FSM that set to true or false an specific animation bool in my characters Animator depending on local bools within the playmaker FSM. So my idea is to link those local bools to my dialogue system using Sync Bool playmaker action and let Dialogue System to set those bools values.

This is an example of a dialogue ( all in one node ) that could have different expressions:

" I´m not sure which direction he took ( thoughtful ),IT could be that road on the right ( Right hand raised ) BUT it´s hard to know without my glasses ( both hands slightly raised ) . I don't see a damn!! ( Angry ). "

I would like to set a bool at the beginning of the dialogue, then another at the words "IT" "BUT" and "I".

I could set different nodes for each part of this dialogue and then set the bool values in the script slot but I hope there is a way of keeping my dialogue together in a node and be able to set bool values at different specific words.

Any help?.

Re: Set a bool value at an specific word within a dialogue node

Posted: Thu Jul 04, 2024 2:40 pm
by Tony Li
Hi,

Here are three ways to approach it:

1. Make a subclass of the typewriter effect (e.g., UnityUITypewriterEffect) and override some methods to extract a new custom token that you'd define. When the typewriter gets to that token, perform your action (e.g., play animation).

2. Easier: Or you can write a short script with an OnConversationLine method. Define a string to recognize (e.g., "[showUI]"). In OnConversationLine, extract that tag, and identify the string that precedes it. Then set a timer to show the UI after the time it will take to type the preceding string. Call ConversationView.GetDefaultSubtitleDuration(string) to determine the time to wait.

3. Easiest: Use Text Animator. You can define your own tags, and Text Animator will invoke them when its typewriter effect gets to the tag.

Re: Set a bool value at an specific word within a dialogue node

Posted: Fri Jul 05, 2024 4:09 am
by Jorillan
Hi Tony. Thank you for your answer.

I think I got what I need for my conversations totally wrong :? . I don´t use typewriter since my dialogues appear all at once and actually the dialogue audio is what set the timing. So I guess what I really need is to set a bool at an specific time of the audio of a dialogue node. This way, for the example dialogue I posted before, I will have to set a bool at the beginning of the audio an then another ones at 3 different time of the audio.

Re: Set a bool value at an specific word within a dialogue node

Posted: Fri Jul 05, 2024 10:47 am
by Tony Li
Hi,

You could do it manually. For example, examine your audio file and determine the times at which IT, BUT, and I appear. For example, say it's 1.1 seconds, 2.3 seconds, and 4.7 seconds. Then use sequencer commands to perform actions at those times. If you were using animator trigger parameters on the speaker's Animator component, it might look like:

Code: Select all

AnimatorTrigger(thoughtful)@0;
AnimatorTrigger(raise_right_hand)@1.1;
AnimatorTrigger(raise_both_hands)@2.3;
AnimatorTrigger(angry)@4.6;
{{default}}
Side note: The {{default}} at the end is a special keyword that tells the sequence to play the Dialogue Manager's Default Sequence.

Alternatively, you could use Timeline. In this case, I'd create a small timeline that plays the audio and controls the animation/bools. Then use the Timeline() sequencer command to play this timeline with the dialogue entry.

Re: Set a bool value at an specific word within a dialogue node

Posted: Fri Jul 05, 2024 1:48 pm
by Jorillan
Hi Tony.

Are those commands setting animator bool parameter (bool) to true or switching the value to the opposite it is currently set? and to which animator is sending the command?

Re: Set a bool value at an specific word within a dialogue node

Posted: Fri Jul 05, 2024 2:20 pm
by Tony Li
Hi,

The Dialogue System has a built-in library of several sequencer commands, including several Animator***() commands. And you can also write your own sequencer commands to do whatever you want. This reference page explains sequences and which GameObjects are used: Cutscene Sequences

Re: Set a bool value at an specific word within a dialogue node

Posted: Fri Jul 05, 2024 2:58 pm
by Jorillan
Thank you Toni,

I´m an artist making a game with Playmaker so coding is no my strong point but I will read those references you gave me and find my way through.

Thank you.

Re: Set a bool value at an specific word within a dialogue node

Posted: Fri Jul 05, 2024 3:23 pm
by Tony Li
Hi,

Fortunately sequencer commands were designed for non-programmers. They still do have a learning curve since they're text-based, but the rules are simpler than in programming languages.

Since you're using Playmaker, make sure you've imported the Playmaker Support packages. (See Playmaker Support.)

Since you already have a Playmaker FSM that handles your animation, I recommend using the FSMEvent() sequencer command instead of Animator***() sequencer commands. In your FSM, create user events such as THOUGHTFUL, RAISE_RIGHT_HAND, RAISE_BOTH_HANDS, and ANGRY that change your FSM bools:

fsm.png
fsm.png (6.35 KiB) Viewed 429 times

Then in your dialogue entry, set the Sequence field to something like:

Code: Select all

FSMEvent(THOUGHTFUL)@0;
FSMEvent(RAISE_RIGHT_HAND)@1.1;
FSMEvent(RAISE_BOTH_HANDS)@2.3;
FSMEvent(ANGRY )@4.6;
{{default}}
This assumes the dialogue entry is spoken by the character that has this Playmaker FSM. If you need to send the FSM events to a different character's GameObject, you'll need to specify the GameObject, such as this command to send the FSM event to FSM on the GameObject named "Player":

Code: Select all

FSMEvent(THOUGHTFUL, Player)

Re: Set a bool value at an specific word within a dialogue node

Posted: Fri Jul 05, 2024 3:34 pm
by Jorillan
Great, thank you!!

That looks way better for me. I think I can make this work now.

Thank you Toni. ;)

Re: Set a bool value at an specific word within a dialogue node

Posted: Fri Jul 05, 2024 3:46 pm
by Tony Li
Glad to help! If any questions come up, just let me know.