Triggering Animation Changes for characters using Dialog Entry Variables

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
2linescrossed
Posts: 30
Joined: Tue May 16, 2023 10:37 pm

Triggering Animation Changes for characters using Dialog Entry Variables

Post by 2linescrossed »

Hi, just got a few questions on how to best make use of custom fields to trigger animations!

To briefly summarize my circumstances, I've got a few basic, simple animations (they're just different expressions, so not quite animations outside of bobbing up and down) for my characters.
I also have two specific fields in the DialogDatabase's Dialogue Entries section in Templates; Animation ID (text) and Mood ID, a custom field enum dropdown.

Currently, I've been using Mood ID to determine the sound type of voicelines/SFX, with the Animation ID acting as filler in case I want to do an animation that may differ from the Mood.

What I currently don't know is, how do I use Animation ID to actually act as a trigger to cause the speaker/any number of conversants to change animations or expressions? I can change it from text type if a different one is more suitable, but I'm not sure what the best infrastructrure for this should be.

Generally speaking, there's usually around 3 or 4 NPCs on screen for these conversations at a given time. If I wanted to change all their expressions, (despite there only being potentially 2 people in the actual conversation), what should I do?
There aren't consistent gameobjects or actors around, but I do have references to the specific NPCs present in a list, just that I can't guarantee a specific actor is present besides the two actually having the conversation.
2linescrossed
Posts: 30
Joined: Tue May 16, 2023 10:37 pm

Re: Triggering Animation Changes for characters using Dialog Entry Variables

Post by 2linescrossed »

As a sub-question, I've been trying to get a name input field working using the guide posted here: https://pixelcrushers.com/phpbb/viewtop ... f=3&t=6338

But I'm having some difficulty understanding some parts of it, specifically how to refer to an Actor's display name using markup. It says to use "To show the player's name in text, use the [var=Actor] markup tag in text.", which doesn't seem to work. I've looked on that particular documentation page, but it only tells me how to use the variables rather than actor values. I'm definitely doing it wrong, as I'm getting 'nil' in both the text box and the actual dialog. What's the right way to do it? I'll probably re-add clear to it later so there's no 'nil' in the input box, but I still want to know how to properly access actor values/Display names.

In addition, should I ever use 'blank' nodes that purely have sequences or scripts on them, or should I avoid those if I can?
User avatar
Tony Li
Posts: 20990
Joined: Thu Jul 18, 2013 1:27 pm

Re: Triggering Animation Changes for characters using Dialog Entry Variables

Post by Tony Li »

Blank Nodes
Blank nodes are totally fine. They're often used to make stuff happen without showing text onscreen. Make sure your blank nodes advance on their own, without requiring the player to click a continue button, because there will be no continue button since it's not showing a subtitle panel.

Names
If you know the actor's name, such as "Player", you can use: [lua(Actor["Player"].Display_Name)] instead of [var=Actor]. However, if [var=Actor] isn't working but you think it should be, read Character GameObject Assignments. Maybe the conversation is using the wrong GameObject(s).

Animation Triggers
Please correct me if I'm misunderstanding what you want to do. If you want to set an animator trigger on a character's GameObject, it might be simpler to use an AnimatorTrigger() sequencer command. For example, to set the animator trigger "Jump_Out" on the dialogue entry's speaker, and then 0.5 seconds later set the animator trigger "Scared" on a character named Joe, you could use this Sequence:

Code: Select all

AnimatorTrigger(Jump_Out, speaker);
AnimatorTrigger(Scared, Joe)@0.5
The special keyword "speaker" refers to the character GameObject that's speaking the current dialogue entry.

If Joe isn't present, the Dialogue System will log a warning to the Console but otherwise continue as normal.

If you don't want the warning, you could write a custom sequencer command that does the same thing as AnimatorTrigger() but doesn't log a warning if the subject isn't present.

If you don't want to use sequencer commands in the Sequence field, you could construct the sequence at runtime using an OnConversationLine(Subtitle) method, such as:

Code: Select all

void OnConversationLine(Subtitle subtitle)
{
    var trigger = Field.LookupValue(subtitle.dialogueEntry.fields, "Animation ID");
    if (!string.IsNullOrEmpty(trigger))
    {
        subtitle.sequence = $"AnimatorTrigger({trigger}, speaker); {subtitle.sequence}";
    }
}
Or, if you don't want to use sequencer commands at all, you could process the animation directly in OnConversationLine.

The drawback of OnConversationLine is that, as written above, it really only works for the speaker. You'd have to figure out a way to specify animations on other characters, too.
2linescrossed
Posts: 30
Joined: Tue May 16, 2023 10:37 pm

Re: Triggering Animation Changes for characters using Dialog Entry Variables

Post by 2linescrossed »

Thanks for the detailed response, Tony!
I believe you answered most of my questions, though I'm still having some difficulty with getting the basic PlayerName change working.

I just want to have the player input their name, which then updates their display name in-game. I probably can't update the actual Actor name, because wouldn't that break all the actor dialog vars in the process?

"TextInput(Text Field UI, Your name?, PlayerName, 30)" is what I'm attempting to use, but it creates a 'nil' in the text field, and when the dialog attempts to access it, it yields a nil as well.

Then, "ChangeActorName("Player", Variable["playerName"])", in a next, blank node,
and finally, "[var=Player], huh? Well nice to meetcha!" at the end.
Currently, there's no actual object in the scene that serves as the player's actor, as in the context of my game the protagonist is mostly mute (outside of a few one on one conversations where the player can choose options). Could that be affecting things, whether now or in future? The player is never 'seen', so I've mostly been getting away with it.
User avatar
Tony Li
Posts: 20990
Joined: Thu Jul 18, 2013 1:27 pm

Re: Triggering Animation Changes for characters using Dialog Entry Variables

Post by Tony Li »

Hi,

Since you're storing the player's input in the variable PlayerName, the markup tag should be [var=PlayerName].

However, the ChangeActorName() Lua function will also set the actor's "Display Name" field. So you can use this tag:

[lua(Actor["Player"].Display_Name)]

as in:

[lua(Actor["Player"].Display_Name)], huh? Well nice to meetcha!
xyztankman
Posts: 45
Joined: Mon Jun 21, 2021 7:48 pm

Re: Triggering Animation Changes for characters using Dialog Entry Variables

Post by xyztankman »

Hey Tony! Came across this while researching. Do you have the method for finding the character display name in script? I'm trying to search the display name I just set but can't find it. I have this in the script below:

Code: Select all

CharacterNameText.text = DialogueLua.GetActorField("BigBoss", DialogueActor.GetActorName).asString;
Can't seem to find where to get the display name portion without using a secondary value that I created for nicknames.
User avatar
Tony Li
Posts: 20990
Joined: Thu Jul 18, 2013 1:27 pm

Re: Triggering Animation Changes for characters using Dialog Entry Variables

Post by Tony Li »

Hi,

Try:

Code: Select all

CharacterNameText.text = DialogueLua.GetActorField("BigBoss", "Display Name").asString;
xyztankman
Posts: 45
Joined: Mon Jun 21, 2021 7:48 pm

Re: Triggering Animation Changes for characters using Dialog Entry Variables

Post by xyztankman »

Yep that was it! Simple but totally missed it. Thanks!
User avatar
Tony Li
Posts: 20990
Joined: Thu Jul 18, 2013 1:27 pm

Re: Triggering Animation Changes for characters using Dialog Entry Variables

Post by Tony Li »

Glad to help!
Post Reply