Page 1 of 2
Best way to set up Animations in Sequences
Posted: Fri Feb 25, 2022 2:44 pm
by Rose
Hi! I'm making a top down 2D game that has a lot of animations. There's going to be a lot of animations in the dialogue scenes and I'm wondering the best way to set them up.
I've looked at the documentation and added the following to the Sequence at the point an animation will start (but obviously with my Animation state and character name there instead):
Code: Select all
AnimatorPlay(Idle, Fred) (Plays the "Idle" state on Fred's Animator.)
However, right now nothing is happening on that node when I play test. The character just stands still. Is there something else I should be adding to the Sequence too or something I may have missed in my set up?
Also, is there a line for the Sequencer if the character were to move 1 space left, right, down, or up in a scene for a top down game? or is the only way to use MoveTo(GameObject, speaker) and make them move to an object?
Re: Best way to set up Animations in Sequences
Posted: Fri Feb 25, 2022 4:20 pm
by Tony Li
Hi,
Rose wrote: ↑Fri Feb 25, 2022 2:44 pmHi! I'm making a top down 2D game that has a lot of animations. There's going to be a lot of animations in the dialogue scenes and I'm wondering the best way to set them up.
I've looked at the documentation and added the following to the Sequence at the point an animation will start (but obviously with my Animation state and character name there instead):
Code: Select all
AnimatorPlay(Idle, Fred) (Plays the "Idle" state on Fred's Animator.)
However, right now nothing is happening on that node when I play test. The character just stands still. Is there something else I should be adding to the Sequence too or something I may have missed in my set up?
First make sure there any no errors or warnings in the Console when you play that sequencer command. Also, remove the comment "(Plays the "Idle" state on Fred's Animator.)" as that's not part of the sequence.
To keep things simple in this reply, I'll assume the animator state is Idle and the character is Fred.
If there are no errors or warnings, make sure "Fred" uniquely identifies a GameObject by Dialogue Actor or by GameObject name, and that it has an Animator component. The animator controller assigned to the Animator component should have a state named "Idle" (exact spelling and capitalization). Also check any transition arrows coming out of the Idle state, and any transition arrows coming out of Any_State, to make sure they're not immediately transitioning away from Idle as soon as Idle starts playing.
Rose wrote: ↑Fri Feb 25, 2022 2:44 pmAlso, is there a line for the Sequencer if the character were to move 1 space left, right, down, or up in a scene for a top down game? or is the only way to use MoveTo(GameObject, speaker) and make them move to an object?
You'll need to write a custom sequencer command for that. See
part 6 of the
Cutscene Sequence Tutorials.
Re: Best way to set up Animations in Sequences
Posted: Fri Feb 25, 2022 7:29 pm
by Rose
Dialogue System: Sequencer: AnimatorPlay(Walk, Player, fade=0, layer=-1)
That is what is showing up on Info. No error. I changed the name of Player to something that doesn't exist just to see if an error pops up for that and one did, so it seems it is recognising it fine.
At a closer look, the animation does play, but only for like a millisecond before it changes back to idle again.
I'm currently checking through my project to see what could be the problem. I've disabled my PlayerMovement script to see if it was that interfering but the animation plays only for a millisecond whether that script is enabled or disabled.
Re: Best way to set up Animations in Sequences
Posted: Fri Feb 25, 2022 8:47 pm
by Tony Li
Hi Rose,
It sounds like something outside the Dialogue System is setting it back. In your animator controller, is there a transition arrow from anything to Idle?
Maybe your PlayerMovement script is still controlling the animator somehow even if it's disabled. Or maybe some other script is setting it to Idle.
What's the complete sequence? If it's something like this:
Code: Select all
AnimatorPlay(Walk, Player);
AnimatorPlay(Idle, Player)
then that could be causing the issue. Unless you use the "@" syntax to specify timing, a command will run as soon as the dialogue entry node starts. In the sequence above, neither command has "@", so the first one will play "Walk" and then the second one will immediately change to "Idle". If you wanted to walk for 2 seconds and then switch to Idle, you could do something like:
Code: Select all
AnimatorPlay(Walk, Player);
AnimatorPlay(Idle, Player)@2
If this sequence is on a node spoken by the player actor, you can omit the GameObject name:
Code: Select all
AnimatorPlay(Walk);
AnimatorPlay(Idle)@2
I also recommend putting "required" in front of the second command:
Code: Select all
AnimatorPlay(Walk);
required AnimatorPlay(Idle)@2
This way, if the player clicks the continue button to skip ahead before 2 seconds have elapsed, it will still play the Idle animation.
Re: Best way to set up Animations in Sequences
Posted: Fri Feb 25, 2022 9:34 pm
by Rose
Just tried all your suggestions and still no luck! (Though I've kept a record so I can use them when we finally get this working!
)
I think you're right that it must be something outside the Dialogue System...
Funnily enough, I just tried using the MoveTo Sequence and the character just slides across the screen instead of walking. It seems it really want to stay idle lol.
Though when I use my controller to move them, they walk then. Hmm...
I disabled all the components attached to my player (apart from Animator) and deleted the Player Movement script to see... and it's still happening so perhaps the culprit
might be the Animator controller and the way I've set it up...
Is there anything with this set up that could be causing an issue? I just muted the arrow that goes from Walk to Idle... and guess what! The player starts walking!
Trouble with that is they never go back to being idle lol.
Re: Best way to set up Animations in Sequences
Posted: Fri Feb 25, 2022 10:01 pm
by Tony Li
That transition from Walk to Idle is the culprit.
There are two ways to address it:
1. Remove or mute the transition, and use something like "required AnimatorPlay(Idle, Player)@2" to go back to Idle after 2 seconds.
2. Or configure the transitions to check a Boolean animator parameter -- for example, named "IsWalking". Configure the Idle-->Walk transition to require IsWalking is true, and Walk-->Idle to require IsWalking is false. Then use AnimatorBool() commands instead of AnimatorPlay().
Re: Best way to set up Animations in Sequences
Posted: Sat Feb 26, 2022 10:40 am
by Rose
Brilliant! It's working now. Glad we figured out the culprit.
I decided to go with the 2nd option you suggested so I'll be using AnimatorBool. It was a little easier for me to get that one set up. If AnimatorBool is totally fine to use as a replacement for AnimatorPlay, I'll be happy to use that for the Sequences instead.
Re: Best way to set up Animations in Sequences
Posted: Sat Feb 26, 2022 11:05 am
by Tony Li
Hi,
Sure! AnimatorBool() is totally fine to use.
Re: Best way to set up Animations in Sequences
Posted: Sat Feb 26, 2022 2:05 pm
by Rose
So something strange is happening…
I’m using this Sequence for testing purposes to see if animations are working:
Code: Select all
AnimatorBool(IsWalking, true, Player);
required AnimatorBool(IsWalking, false, Player)@5
It works, but only on the first dialogue node. On the dialogue nodes that come after, the Player stays idle even when IsWalking is ticked. (I checked the Animator during test play and IsWalking always gets ticked when the Sequence happens so at least it’s recognising that)
I’ve disabled Player Movement, and started a fresh new conversation with 3 empty dialogue nodes (no events and nothing written in the Sequences) and it still only works on the first dialogue node but not the ones that come after.
I’m messing around trying to figure out what the problem could be and wondered if you might know the culprit for this one lol!
Re: Best way to set up Animations in Sequences
Posted: Sat Feb 26, 2022 2:35 pm
by Tony Li
Hi,
It sounds like the issues might be in the animator. Inspect the transition arrows, and untick "Has Exit Time" if it's ticked.