set animator parameter in a dialogue entry

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
joeylu
Posts: 111
Joined: Sun May 17, 2020 1:07 pm

set animator parameter in a dialogue entry

Post by joeylu »

for instance,
I have a player triggers a conversation after onTrigger enter to a npc
then the conversation starts
at certain dialogue entry point, I want to play another gameobject (not player, not npc) animation
I need to set that gameobject's animator parameter at some point

what I'm doing right now add some variable field in that dialogue entry, then write a script to find those variables and do the animator.setxxx with those conditions

is there any efficient way without writing additional scripts, use sequences to set animator state? tks
User avatar
Tony Li
Posts: 21678
Joined: Thu Jul 18, 2013 1:27 pm

Re: set animator parameter in a dialogue entry

Post by Tony Li »

Hi,

Yes, this is exactly what sequences are for. Let's say the GameObject is named Bomb, and you want to set its Explode trigger parameter. Set the dialogue entry node's Sequence field to:

Code: Select all

{{default}};
AnimatorTrigger(Explode, Bomb)
The first line plays the Dialogue Manager's Default Sequence. The second line adds a command to set the Explode trigger on the GameObject named Bomb.

More info: Cutscene Sequences, Tutorials
joeylu
Posts: 111
Joined: Sun May 17, 2020 1:07 pm

Re: set animator parameter in a dialogue entry

Post by joeylu »

nice, so if I want to set a gameobject in the scene (has animator controller)
let's say the parameter is a bool, so I can add something like the following in the sequence from any dialogue entry inside of a conversation right?

AnimatorBool(walking, true, myobject_name)

one question, for the game object name, if that game object contains space, does it matter?
User avatar
Tony Li
Posts: 21678
Joined: Thu Jul 18, 2013 1:27 pm

Re: set animator parameter in a dialogue entry

Post by Tony Li »

Yes, that's all correct. GameObject names can contain spaces.
joeylu
Posts: 111
Joined: Sun May 17, 2020 1:07 pm

Re: set animator parameter in a dialogue entry

Post by joeylu »

sorry Tony, just missed an important issue, what if I have two game objects that have same name? tks
User avatar
Tony Li
Posts: 21678
Joined: Thu Jul 18, 2013 1:27 pm

Re: set animator parameter in a dialogue entry

Post by Tony Li »

In that case you'll need to name one differently. Or, if one of them is the dialogue entry node's speaker or listener, you can use 'speaker' or 'listener' instead of the GameObject name.

Alternatively, you can use scene events.
joeylu
Posts: 111
Joined: Sun May 17, 2020 1:07 pm

Re: set animator parameter in a dialogue entry

Post by joeylu »

tks Tony, sure I can name it differently :)

speaking of the "speaker" or "listener", does "speaker" means "actor" and "listener" means "Conversant"? otherwise how or where do I set them as "listener" or "speaker"

as it for scen events, that was the first place I was look for but turns out UnityEvent doesn't not support animator parameter functions because it takes two parameters, or am I missing anything?
User avatar
Tony Li
Posts: 21678
Joined: Thu Jul 18, 2013 1:27 pm

Re: set animator parameter in a dialogue entry

Post by Tony Li »

joeylu wrote: Fri Aug 28, 2020 3:17 pmspeaking of the "speaker" or "listener", does "speaker" means "actor" and "listener" means "Conversant"? otherwise how or where do I set them as "listener" or "speaker"
'speaker' and 'listener' change with each dialogue entry node.

'speaker' is the GameObject associated with the node's Actor.
'listener' is the GameObject associated with the node's Conversant.
joeylu wrote: Fri Aug 28, 2020 3:17 pmas it for scen events, that was the first place I was look for but turns out UnityEvent doesn't not support animator parameter functions because it takes two parameters, or am I missing anything?
UnityEvents can call an Animator's Play() and SetTrigger() methods. If you use UnityEvents, you can use those methods.
Post Reply