Page 1 of 1

set animator parameter in a dialogue entry

Posted: Thu Aug 27, 2020 11:19 am
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

Re: set animator parameter in a dialogue entry

Posted: Thu Aug 27, 2020 12:04 pm
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

Re: set animator parameter in a dialogue entry

Posted: Thu Aug 27, 2020 12:57 pm
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?

Re: set animator parameter in a dialogue entry

Posted: Thu Aug 27, 2020 1:06 pm
by Tony Li
Yes, that's all correct. GameObject names can contain spaces.

Re: set animator parameter in a dialogue entry

Posted: Fri Aug 28, 2020 4:56 am
by joeylu
sorry Tony, just missed an important issue, what if I have two game objects that have same name? tks

Re: set animator parameter in a dialogue entry

Posted: Fri Aug 28, 2020 12:50 pm
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.

Re: set animator parameter in a dialogue entry

Posted: Fri Aug 28, 2020 3:17 pm
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?

Re: set animator parameter in a dialogue entry

Posted: Fri Aug 28, 2020 3:23 pm
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.