Page 1 of 2
Playing an animation upon starting a dialogue
Posted: Sun Jul 30, 2023 12:41 am
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?
Re: Playing an animation upon starting a dialogue
Posted: Sun Jul 30, 2023 9:32 am
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 (6.64 KiB) Viewed 524 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:
(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 (6.92 KiB) Viewed 524 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.
Re: Playing an animation upon starting a dialogue
Posted: Sun Jul 30, 2023 2:57 pm
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
Re: Playing an animation upon starting a dialogue
Posted: Sun Jul 30, 2023 3:21 pm
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:
Re: Playing an animation upon starting a dialogue
Posted: Sun Jul 30, 2023 5:22 pm
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?
Re: Playing an animation upon starting a dialogue
Posted: Sun Jul 30, 2023 5:35 pm
by Tony Li
Yup! For a door, you probably don't even need an Idle. Just Open and Close states.
Re: Playing an animation upon starting a dialogue
Posted: Wed Aug 02, 2023 9:33 pm
by simplepleasuresdxy
Re: Playing an animation upon starting a dialogue
Posted: Wed Aug 02, 2023 10:16 pm
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:
If your GameObject is named "Fade to Blur", then try:
Re: Playing an animation upon starting a dialogue
Posted: Wed Aug 02, 2023 10:56 pm
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?
Re: Playing an animation upon starting a dialogue
Posted: Thu Aug 03, 2023 2:03 am
by simplepleasuresdxy
never mind blur blur stopped working ... ugh