Page 1 of 2
Sequence of animations with AnimatorPlay()
Posted: Sat Oct 24, 2020 2:50 pm
by Pendergast
Hi !
So, i am trying to play multiple animations with the sequencer ; i tried the animation() command, it worked but it messed with my animations. Is there any way to use AnimatorPlay() to do multiples animations like animation(), since AnimatorPlay() isn't messing with my animations ?
Exemple: With Animation(), i can do: Animation(Idle, Merevin, Talk, Idle). I want to do the same thing but with the Animator component !
Also, i tried to use the Audio() command, but it won't work (it says "Dialogue System: Sequencer: Audio() command: clip 'Taverne' could not be found or loaded." and i have an audio component on a gameobject, so i don't understand !)
Thank you in advance !
Re: Sequence of animations with AnimatorPlay()
Posted: Sat Oct 24, 2020 3:41 pm
by Tony Li
Hi,
Here are two ways to do multiple animations with an Animator:
1. Create transitions from one animator state to the next:
- animatorPlayTransitions.png (11.04 KiB) Viewed 783 times
If you use:
it will play Dance, then Bow, then Rest, then Idle.
2. Or use AnimatorPlayWait() with messages:
Code: Select all
AnimatorPlayWait(Dance)->Message(Danced);
AnimatorPlayWait(Bow)@Message(Danced)->Message(Bowed);
AnimatorPlayWait(Rest)@Message(Bowed)->Message(Rested);
required AnimatorPlayWait(Idle)->Message(Rested);
This solution has two advantages:
a. You don't have to create any transition arrows in your Animator Controller.
b. If the player skips ahead, the 'required' keyword guarantees that the animations will stop, and the character will return to the Idle state.
To use Audio() or AudioWait(), put your audio clips in a folder named Resources. Your project can have any number of Resources folders anywhere in the Assets folder structure.
If you have many audio clips, you can switch to Addressables or assetbundles later. You won't have to change any of your sequences to do that.
Re: Sequence of animations with AnimatorPlay()
Posted: Sat Oct 24, 2020 4:00 pm
by Pendergast
Thank you !! It helped a lot !
The Audio() command works fine now, but i have trouble with stopping one audio to play another one. :/
Re: Sequence of animations with AnimatorPlay()
Posted: Sat Oct 24, 2020 4:38 pm
by Tony Li
Try using AudioWait().
The Audio() command starts an audio clip and just lets it play without controlling it any further.
AudioWait() waits until the audio is done. If the subtitle is skipped before the audio is done -- for example, by clicking the continue button -- it will stop the audio.
Re: Sequence of animations with AnimatorPlay()
Posted: Sat Oct 24, 2020 4:56 pm
by Pendergast
Sadly, it doesn't work for what i want to do :/
It's for a visual novel game ; during a long time, i need an audio playing in loop in the background ; then change it when i tell it to do (change of ambiance/mood). AudioWait() stops right after the message where i used it is skipped
Also, another problem, i tried to use AudioWait() on the Start node and it broke the game at start ; when i use Audio(), it works :/
Re: Sequence of animations with AnimatorPlay()
Posted: Sat Oct 24, 2020 5:04 pm
by Tony Li
Hi,
Avoid putting anything in <START>. Leave it untouched, and add an empty node after <START> to play your sequencer commands. If you're using a continue button, you can include:
to make that node immediately move to the next one after running the sequence.
For the background music, you're correct -- use Audio(). Here is the manual reference:
Audio() Sequencer Command
Set up a GameObject with your background music audio source. Tick the Loop checkbox. Then provide the GameObject name to Audio(). For example, if the GameObject is named "Music", and you want to play an audio clip song named "Relación":
This will find the GameObject named "Music" and use its audio source to play Relación.
Re: Sequence of animations with AnimatorPlay()
Posted: Sat Oct 24, 2020 5:25 pm
by Pendergast
Thanks for the advice about the <Start> node !
I tried to use the gameobject and audio() method ; but it seems i still can't switch audio with the sequencer. I had an error :
Dialogue System: Lua code 'return Audio(romance, Romance_01);
Continue()' threw exception 'Tried to invoke a function call on a non-function value. If you're calling a function, is it registered with Lua?'
(i used "Audio(romance, Romance_01);
Continue()" command)
Re: Sequence of animations with AnimatorPlay()
Posted: Sat Oct 24, 2020 8:42 pm
by Tony Li
Hi,
Put those commands in the Sequence field.
Re: Sequence of animations with AnimatorPlay()
Posted: Sun Oct 25, 2020 6:17 am
by Pendergast
Hi,
It's already in the Sequence field ; but restarting unity solved my problem !
And i still can't switch between multiple audio :/ And the AudioWait() isn't good for what i want to do. Do i have to code something myself to make what i want work ?
I saw that AudioStop() doesn't work with the Audio() command, is there another way ?
Thank you for your help, by the way !!
Re: Sequence of animations with AnimatorPlay()
Posted: Sun Oct 25, 2020 9:14 am
by Tony Li
Hi,
It looks like you have multiple GameObjects, each with its own Audio Source and audio clip. If that's correct, then use the SendMessage() sequencer command to tell it to play and stop:
Code: Select all
SendMessage(Stop,,Tavern_01); // Call Stop() on GameObject Tavern_01.
SendMessage(Play,,Romance_01); // Call Play() on GameObject Romance_01.
(Note the two commas between Stop and Tavern_01. This is because Stop() does not need to receive a parameter.)
I misunderstood. I thought you had a single GameObject -- for example, named "Music" -- and you wanted to play all of the background music files on it. If you want to instead use a single GameObject like this, use Audio():
Code: Select all
Audio(Taverne, Music); // Play Taverne on the Audio Source of the GameObject named Music.
Later...
Code: Select all
Audio(romance, Music); // Play romance on the Audio Source of the GameObject named Music.
In this case, Tavern and romance should be in a folder named Resources.