How could I write a generic sequence that always uses the NPC?

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
AoF
Posts: 241
Joined: Sun May 12, 2019 8:36 pm

How could I write a generic sequence that always uses the NPC?

Post by AoF »

Hello! I'm making a VN, and I often need to change the character's expressions in the conversation. Right now I have an idle, upset, and happy animation. So in parts of the conversation, I'll use SpineAnimation(idle,Eva) or SpineAnimation(happy,Eva). But if it's a conversation with Sarah, I'd want to use SpineAnimation(idle,Sarah) instead. I'm looking for a way to generically say, "idle" and have it do the right thing regardless of the conversation. I think shortcuts are the right tool for the job, but I'm not sure.

There's one part I'm stuck on: These changes in animation don't always happen when the NPC talks, sometimes they react to what the player says. For that reason, I don't think I can use speaker or listener as the variable. I could use it if I were to create an {{idleSpeaker}} and {{idleListener}} shortcut and that wouldn't be so bad, but it would be even more convenient if I could just say {{idle}} and have it do the right thing. Is there a way to do that?

This is a first person view game, so I'd never want the Player to be animated, it'd always be the NPC.
User avatar
Tony Li
Posts: 22056
Joined: Thu Jul 18, 2013 1:27 pm

Re: How could I write a generic sequence that always uses the NPC?

Post by Tony Li »

Is there always one NPC onscreen at a time? Or can multiple be onscreen?

I think you should generally be able to use 'speaker' or 'listener'. If you want to affect the NPC while she's speaking, use 'speaker'. If you want to affect her while the player is speaking, use 'listener'.


Here are some extra ideas:

Like with Dialogue Text, you can use [var=variableName] in Sequence fields to reference Dialogue System variables. For example, say you've assigned the string "IdleRelaxed" to a variable named IdleAnimation. You can set the Sequence to:

Code: Select all

SpineAnimation([var=IdleAnimation])
This will be equivalent to:

Code: Select all

SpineAnimation(IdleRelaxed)

Building on that, when a conversation starts, it automatically sets these 4 variables:
  • Actor: The display name of the conversation's primary actor (typically the player).
  • Conversant: The display name of the conversation's primary conversant (typically an NPC).
  • ActorIndex: The Actor[] table index of the actor, provided for optional low-level Lua code.
  • ConversantIndex: The Actor[] table index of the conversant.
If your conversant's display name is the same as its GameObject name, you can do this:

Code: Select all

SpineAnimation(idle, [var=Conversant])
The thing is that this isn't any better than something like:

Code: Select all

SpineAnimation(idle, listener)
except that it always uses the conversation's conversant regardless of whether the conversant is speaking or listening in this line. So I'm not sure that it's useful by itself like this.


But, going even further, you can also use the the [lua(code)] markup tag in Sequence fields. Here's one way you can use it:

1. Add a custom field named "IdleSequence" to your actor.
On Eva, set it to: SpineAnimation(idle,Eva).
On Sarah, set it to: SpineAnimation(idle,Sarah).

2. When you want the conversant to idle, you can use this Sequence:

Code: Select all

[lua(Actor[Variable["ConversantIndex"]].IdleSequence)]
At runtime, it gets interpreted like this:
  • [lua(Actor[Variable["ConversantIndex"]].IdleSequence)]
  • --> [lua(Actor["Sarah"].IdleSequence)]
  • --> SpineAnimation(idle, Eva)

Then again shortcuts may be exactly what you want. To me it seems like 'speaker' and 'listener' should suffice, but I laid out some other ideas above in case I completely missed the problem that you've encountered. Hopefully one of them will help.
AoF
Posts: 241
Joined: Sun May 12, 2019 8:36 pm

Re: How could I write a generic sequence that always uses the NPC?

Post by AoF »

Tony Li wrote: Tue May 28, 2019 5:35 pm Is there always one NPC onscreen at a time? Or can multiple be onscreen?
There's usually one, but there could be multiple. In the case of multiple, I figured I'd just use specific sequences and skip the shortcuts.
The thing is that this isn't any better than something like...
Well, when I wrap it all in an {{idle}} I think it's pretty good and saves me a bunch of typing long term. Every 3 nodes I'll probably have to type out an animation change, so it'll add up.

How does that Conversant variable get set? Is it from the trigger's Action? Is it from the conversation's start node? Is it somewhere else? I worry the whole thing could fall apart depending on who speaks first.
User avatar
Tony Li
Posts: 22056
Joined: Thu Jul 18, 2013 1:27 pm

Re: How could I write a generic sequence that always uses the NPC?

Post by Tony Li »

Sounds like shortcuts are the way to go for your needs. Remember that you can also set the Dialogue Manager's Default Sequence field. If a dialogue entry node's Sequence is blank, it will use the Dialogue Manager's Default Sequence.

You can override the Dialogue Manager's Default Sequence for a single conversation by inspecting that conversation's properties. (Edit the conversation and click on blank canvas space in the node editor.) Tick the Override Display Settings checkbox for the conversation.
AoF
Posts: 241
Joined: Sun May 12, 2019 8:36 pm

Re: How could I write a generic sequence that always uses the NPC?

Post by AoF »

Ah, that's useful to know.

How does that Conversant variable get set? Is it from the trigger's Action? Is it from the conversation's start node? Is it somewhere else? I worry the whole thing could fall apart depending on who speaks first.
User avatar
Tony Li
Posts: 22056
Joined: Thu Jul 18, 2013 1:27 pm

Re: How could I write a generic sequence that always uses the NPC?

Post by Tony Li »

Yes, it's from the Dialogue System Trigger's Action > Start Conversation.
Post Reply