Animations on NPC lines and PC lines

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
User avatar
Kole90
Posts: 43
Joined: Wed Nov 08, 2017 4:51 am

Animations on NPC lines and PC lines

Post by Kole90 »

Hey Tony, what is the best way to approach this problem? I have 2 animations for NPC, one should be played while he speaks and the second one should be played when he isn't. I thought that maybe Dialogue System has some sort of functions that are called when NPC's nodes are playing and a function when they are not anymore.

Some sort of function/event that is called when then conversation stops and we get our response nodes that are waiting for player to choose and click on them would be good as well.
User avatar
Tony Li
Posts: 22058
Joined: Thu Jul 18, 2013 1:27 pm

Re: Animations on NPC lines and PC lines

Post by Tony Li »

Hi,

Use the node's Sequence field, which uses sequencer commands.

For example, you could set the Sequence to:

Code: Select all

AnimatorPlay(MoveMouth);
required AnimatorPlay(Idle)@{{end}}
The sequence above will play the MoveMouth animator state on the speaker. After a duration determined by the text length ({{end}}), it will play the Idle animator state. The 'required' keyword ensures that it plays Idle even if the player cancels or skips ahead before the {{end}} duration is reached.

Sequences can get way more elaborate than that. I encourage you to read the Cutscene Sequences section of the manual if you're interested in doing more with them.

You can also set the Dialogue Manager's Default Sequence field. If the node's Sequence field is blank, it will use the Dialogue Manager's Default Sequence. This saves you from having to type the same sequence into every node.
User avatar
Kole90
Posts: 43
Joined: Wed Nov 08, 2017 4:51 am

Re: Animations on NPC lines and PC lines

Post by Kole90 »

That sound good, one question though, how do I point the sequence field to a correct animator?

Second thing that pops up to my mind is the default sequence, that sounds like it will save me bunch of time but I have different animations for different characters/conversations, is there a way to set default sequences for every conversation?
User avatar
Tony Li
Posts: 22058
Joined: Thu Jul 18, 2013 1:27 pm

Re: Animations on NPC lines and PC lines

Post by Tony Li »

Kole90 wrote: Tue Jul 03, 2018 9:22 amThat sound good, one question though, how do I point the sequence field to a correct animator?
By default, the AnimatorPlay() command, like most sequencer commands, works on the node's speaker. You can specify a different animator by providing a second parameter. For example, this sequence plays a Roar animator state on the speaker, and then 1 second later a Faint animator state on another GameObject named Fop:

Code: Select all

AnimatorPlay(Roar);
AnimatorPlay(Faint,Fop)@1
The Sequencer Command Reference page describes all the parameters that you can pass to sequencer commands.
Kole90 wrote: Tue Jul 03, 2018 9:22 amSecond thing that pops up to my mind is the default sequence, that sounds like it will save me bunch of time but I have different animations for different characters/conversations, is there a way to set default sequences for every conversation?
Yes. Inspect the conversation's properties by clicking on empty canvas space. In the Inspector, you can override Display Settings > Cutscene & Camera Settings and specify a different Default Sequence.
User avatar
Kole90
Posts: 43
Joined: Wed Nov 08, 2017 4:51 am

Re: Animations on NPC lines and PC lines

Post by Kole90 »

Thanks for the detailed answer, now this may sound dumb but I don't understand what the "node's speaker" is? :oops:

Just throwing questions now while you are online, and will try all of your suggestions once I'm back on my project.
User avatar
Tony Li
Posts: 22058
Joined: Thu Jul 18, 2013 1:27 pm

Re: Animations on NPC lines and PC lines

Post by Tony Li »

If you inspect a node in the Dialogue Editor, the Inspector view will show dropdowns for Actor and Conversant. The node's Actor dropdown specifies the actor that is assigned to the node -- that is, the actor who speaks that line. The Conversant is the actor to whom the line is being spoken.

This next bit is a little confusing, but I would be remiss if I didn't mention it: When you create a conversation, you can specify the conversation's primary Actor and Conversant, also referred to as the primary participants. As you add nodes to the conversation, the editor will alternate between assigning the two primary participants. (If you want to involve additional actors, you can assign them in the node's Actor and Conversant dropdowns.) So the conversation as a whole as a conversation Actor and a conversation Conversant. And each node has a node Actor (the line's speaker) and node Conversant.
User avatar
Kole90
Posts: 43
Joined: Wed Nov 08, 2017 4:51 am

Re: Animations on NPC lines and PC lines

Post by Kole90 »

Thanks for the response. I understood that part that speaker is the actor, but I guess I didn't post my question right. So, if AnimatorPlay() works on the node's speaker, how do I assign the speaker, or better yet how do I assign the gameobject with animator component on it to that speaker/actor so that when I call the sequencer command AnimatorPlay() it uses the correct animator component? Hope that question made sense.
User avatar
Tony Li
Posts: 22058
Joined: Thu Jul 18, 2013 1:27 pm

Re: Animations on NPC lines and PC lines

Post by Tony Li »

When you start a conversation, you can specify the GameObjects to associate with the conversation's primary actor and conversant. (We'll get back to this is a bit.)

If you don't specify GameObjects, the Dialogue System will first check any GameObjects that have Dialogue Actor components. The Dialogue Actor component lets you associate an actor with a GameObject. For example, let's say you're using Unity's Standard Assets FirstPersonController. You can add a Dialogue Actor and set the dropdown to the Player actor to associate the FirstPersonController GameObject with the Player actor.

If the Dialogue System doesn't find any matching Dialogue Actors, it will look for a GameObject whose name matches the actor's name in the dialogue database.

Both of those steps above apply only if you haven't specified GameObjects when starting the conversation. However, when you set up a Dialogue System Trigger, you can explicitly assign GameObjects to the Actor and Conversant fields. In this case, the conversation will use these GameObjects. Similarly, if you start the conversation in a script, you can choose to specify the actor and/or conversant GameObjects. For example, the code below sets the conversation's actor to the GameObject tagged 'Player':

Code: Select all

DialogueManager.StartConversation("My Conversation", GameObject.FindWithTag("Player").transform);
User avatar
Kole90
Posts: 43
Joined: Wed Nov 08, 2017 4:51 am

Re: Animations on NPC lines and PC lines

Post by Kole90 »

Oh so that's why I didn't understand where to assign gameobjects to actors, it's on the Conversation Trigger script, now it makes sense... Thanks Tony for a detailed response as always! ;)
User avatar
Tony Li
Posts: 22058
Joined: Thu Jul 18, 2013 1:27 pm

Re: Animations on NPC lines and PC lines

Post by Tony Li »

Glad to help!
Post Reply