Playing an animation upon starting a dialogue

Announcements, support questions, and discussion for the Dialogue System.
simplepleasuresdxy
Posts: 73
Joined: Tue Jul 25, 2023 1:34 am

Playing an animation upon starting a dialogue

Post by simplepleasuresdxy »

Hi again ...

I think I've seen this tutorial somewhere, but I can't seem to find it. I'm trying to have an animation play out when a certain dialogue is triggered.

Is there a difference when I need to have the animation play on loop and when I want the animation to only play once?
User avatar
Tony Li
Posts: 22119
Joined: Thu Jul 18, 2013 1:27 pm

Re: Playing an animation upon starting a dialogue

Post by Tony Li »

Hi,

Use the AnimatorPlay() or AnimatorPlayWait() sequencer command to play animations.

Say your speaker has an Animator component. Its animator controller asset has two states: Idle and Dance.

idleAndDance.png
idleAndDance.png (6.64 KiB) Viewed 529 times

If you want Idle to play on loop, inspect the Idle state's animation clip. Make sure the Loop checkbox is ticked. To play this in a specific dialogue entry node, use the sequencer command AnimatorPlay(Idle), such as:

Code: Select all

{{default}};
AnimatorPlay(Idle)
(Reminder: The keyword {{default}} tells the sequence to also play the Dialogue Manager's Default Sequence.)

If you want to play the Dance animation and wait for it to finish, use AnimatorPlayWait(Dance). Let's say Dance has an automatic transition to Idle when it's done:

idleAndDance2.png
idleAndDance2.png (6.92 KiB) Viewed 529 times

Then use this sequence:

Code: Select all

{{default}};
AnimatorPlayWait(Dance)
When it's done, the Dance state's transition arrow will make sure the Animator goes back to the Idle state.

If you didn't have that transition arrow (which might not be appropriate in all cases), you could use a more advanced syntax for your sequence:

Code: Select all

{{default}};
AnimatorPlayWait(Dance)->Message(DoneDancing);
required AnimatorPlay(Idle)@Message(DoneDancing)
In this case, the AnimatorPlayWait() command sends the sequencer message "DoneDancing" when it's done. This message is an arbitrary string of your choosing.

The AnimatorPlay() command below it waits for the "DoneDancing" sequencer command. Then it runs. The "required" keyword guarantees that it will run even if the player skips ahead before the Dance animation is done.
simplepleasuresdxy
Posts: 73
Joined: Tue Jul 25, 2023 1:34 am

Re: Playing an animation upon starting a dialogue

Post by simplepleasuresdxy »

What if I do not want an animation linked to a speaker per say? I'm still having trouble with panels and I just think it would be easier if I just had it where I invoked an animation for a separate element

if it's not possible, I'll look into things with the first panel
User avatar
Tony Li
Posts: 22119
Joined: Thu Jul 18, 2013 1:27 pm

Re: Playing an animation upon starting a dialogue

Post by Tony Li »

Hi,

You can specify a GameObject to play the animation on. For example, say you have a GameObject named "Door" with Animator that has "Open" and "Close" animations. To play the Open animation:

Code: Select all

AnimatorPlay(Open, Door)
simplepleasuresdxy
Posts: 73
Joined: Tue Jul 25, 2023 1:34 am

Re: Playing an animation upon starting a dialogue

Post by simplepleasuresdxy »

Awesome! So if I had an animator play the door opening and have an automatic transition to where it goes to idle, I assume the door stays on screen then?
User avatar
Tony Li
Posts: 22119
Joined: Thu Jul 18, 2013 1:27 pm

Re: Playing an animation upon starting a dialogue

Post by Tony Li »

Yup! For a door, you probably don't even need an Idle. Just Open and Close states.
simplepleasuresdxy
Posts: 73
Joined: Tue Jul 25, 2023 1:34 am

Re: Playing an animation upon starting a dialogue

Post by simplepleasuresdxy »

Hi, so I was trying to add the animator bit, but I feel like I'm messing up a whole lot

Basically, I was thinking of creating a blur effect by just taking a picture of the background and creating a blurred image. I would keep the image transparent until a dialogue and just play blur animation to turn on the transparency to full.

I do not know what's going on cause it's just not working, haha.

Image
Image
Image
Image
Image
User avatar
Tony Li
Posts: 22119
Joined: Thu Jul 18, 2013 1:27 pm

Re: Playing an animation upon starting a dialogue

Post by Tony Li »

Hi,

It looks like your animator controller doesn't have a state named "Fade to Blur".

If your GameObject is named "Blur", try this sequencer command:

Code: Select all

AnimatorPlay(Blur, Blur)
If your GameObject is named "Fade to Blur", then try:

Code: Select all

AnimatorPlay(Blur, Fade to Blur)
simplepleasuresdxy
Posts: 73
Joined: Tue Jul 25, 2023 1:34 am

Re: Playing an animation upon starting a dialogue

Post by simplepleasuresdxy »

thank you, blur, blur works, but now it won't stay in the blurred state where the image remains blur. Instead it cuts to the original idle state.

What can I do?
simplepleasuresdxy
Posts: 73
Joined: Tue Jul 25, 2023 1:34 am

Re: Playing an animation upon starting a dialogue

Post by simplepleasuresdxy »

never mind blur blur stopped working ... ugh
Post Reply