Changing Animation State Through Dialogue System Trigger

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
DrewThomasArt
Posts: 60
Joined: Thu Mar 24, 2022 12:07 am

Changing Animation State Through Dialogue System Trigger

Post by DrewThomasArt »

Hello, I have a flashing exclamation point above NPC character's head, and I want it to switch to a "greyed out" version after the player talks to them. I'm trying to add an action in the "Dialogue System Event" tab that changes the animation state of the speech bubble when the player talks to them.

The state starts on 0, and when I change it to 1 manually, it works. But how do I tell the Dialogue system to change the state to 1? There's a bar for me to input the state I want, and I've tried putting "1", "(state, 1)", "AnimatorInt(state, 1)", etc.

Any help is appreciated, thank you.
User avatar
Tony Li
Posts: 21980
Joined: Thu Jul 18, 2013 1:27 pm

Re: Changing Animation State Through Dialogue System Trigger

Post by Tony Li »

Hi,

UnityEvents such as OnConversationEnd() will let you call an Animator's Play() or SetTrigger() method. This means you can make the animator play a state or set a trigger parameter. Assuming your Animator has states named "0" and "1", you can set up the NPC like this:

animatorOnConversationEnd.png
animatorOnConversationEnd.png (47.24 KiB) Viewed 1467 times

Make sure state "1" doesn't automatically transition back to state "0" in the Animator window.

If you need to set an Animator's bool parameter or something else like that, you can use sequencer commands in your conversation. For example, set the last dialogue entry node's Sequence to something like:
  • Dialogue Text: "Goodbye."
  • Sequence: {{default}}; AnimatorBool(GreyedOut, true)
DrewThomasArt
Posts: 60
Joined: Thu Mar 24, 2022 12:07 am

Re: Changing Animation State Through Dialogue System Trigger

Post by DrewThomasArt »

EDIT: Ok I think it's working now that I've added a SetTrigger string at the end of the dialogue. Idk why that works and everything else didn't, but that's alright, thank you

Thank you,

I set the sequence on the last line of dialogue to:
AnimatorBool(isFlashing, false)

In the animator, there is a condition that if the "isFlashing" bool is false, it will transition to the GreyedOut state.
It is still not working

The game object is called "Exclamation", and I also tried;
Exclamation; AnimatorBool(isFlashing, false)
{Exclamation}; AnimatorBool(isFlashing, false)
{{Exclamation}}; AnimatorBool(isFlashing, false)

I'm guessing I'm typing it wrong or I'm not referencing the game object correctly or something?
Last edited by DrewThomasArt on Mon Apr 11, 2022 3:40 pm, edited 1 time in total.
User avatar
Tony Li
Posts: 21980
Joined: Thu Jul 18, 2013 1:27 pm

Re: Changing Animation State Through Dialogue System Trigger

Post by Tony Li »

Hi,

Try this:

Code: Select all

{{default}}; AnimatorBool(isFlashing, false, Exclamation)
If your scene will have more than one GameObject named Exclamation, you might want to add the name of the actor to the GameObject name to make it unique. For example, if the actor is Bob, then name the GameObject "Exclamation Bob" and use:

Code: Select all

{{default}}; AnimatorBool(isFlashing, false, Exclamation Bob)
DrewThomasArt
Posts: 60
Joined: Thu Mar 24, 2022 12:07 am

Re: Changing Animation State Through Dialogue System Trigger

Post by DrewThomasArt »

Tony Li wrote: Mon Apr 11, 2022 3:38 pm Hi,

Try this:

Code: Select all

{{default}}; AnimatorBool(isFlashing, false, Exclamation)
If your scene will have more than one GameObject named Exclamation, you might want to add the name of the actor to the GameObject name to make it unique. For example, if the actor is Bob, then name the GameObject "Exclamation Bob" and use:

Code: Select all

{{default}}; AnimatorBool(isFlashing, false, Exclamation Bob)
Thank you very much, this works as well as changing the Trigger string with an end of dialogue event like you suggested. It just took me a while to figure it out
User avatar
Tony Li
Posts: 21980
Joined: Thu Jul 18, 2013 1:27 pm

Re: Changing Animation State Through Dialogue System Trigger

Post by Tony Li »

Glad to help!
Post Reply