Page 1 of 1

Triggering the animations for a game object sprite instead of a UI sprite

Posted: Sun Jun 11, 2023 10:29 pm
by Basel
Hello,

So I'd like to trigger the facial expressions and animations for a game object sprite instead of one in the UI. The tutorial shows how to do this for UI animations only, as far as I can tell.

1. To change the expressions for a scene game object, would the best way to go about it be to use the scene events in the inspector for the conversation?
2. Is there any way trigger the talking animation on the sprite game object to match the length of the typewriter effect of each conversation block?

Thanks for your help!

Re: Triggering the animations for a game object sprite instead of a UI sprite

Posted: Mon Jun 12, 2023 7:51 am
by Tony Li
Hi,

The answer to both questions is to use cutscene sequences.

For example, say the speaker's game object sprite has an Animator with animator states named "Idle" and "Talk". You can use this sequence to play the Talk animation while the typewriter is typing:

Code: Select all

AnimatorPlay(Talk);
required AnimatorPlay(Idle)@Message(Typed)

Re: Triggering the animations for a game object sprite instead of a UI sprite

Posted: Mon Jun 12, 2023 2:18 pm
by Basel
Thank you for the reply, Tony!
Should there be parameters to trigger Idle and Talk? Right now it looks like the code just seems to make the character Talk nonstop but the Idle doesn't ever trigger. I'm using this code:

Code: Select all

AnimatorPlay(Talk);
required Animator.Play(Mouth_Idle)@Message(Typed)
Not sure what I'm doing wrong.

Re: Triggering the animations for a game object sprite instead of a UI sprite

Posted: Mon Jun 12, 2023 2:50 pm
by Tony Li
Hi,

Check the Console window for warnings.

Also try changing this line:

Code: Select all

required Animator.Play(Mouth_Idle)@Message(Typed)
to this:

Code: Select all

required AnimatorPlay(Mouth_Idle)@Message(Typed)
(Remove the "." between Animator and Play.)

You don't need any parameters for this. AnimatorPlay() tells the animator to play a state directly, without the need for parameter-based transition arrows.

Re: Triggering the animations for a game object sprite instead of a UI sprite

Posted: Mon Jun 12, 2023 5:34 pm
by Basel
Thanks, I can't believe I did that lol! (I also put the two animations in opposite spots in the code.)
I did fix the spelling error and I was still having issues. It took a while for me to figure out since I'm still new to Unity, but it seems like what was causing issues was the fact that I had a transition from the talk animation to mouth_idle in the animator. Any transitions between mouth_idle and talk seems like it made those animations only play once, instead of the entire time the text was being typed. I guess it was something I didn't understand in terms of how animation works in Unity, but leaving this here in case some one has the same problem.

Thank you again!

Re: Triggering the animations for a game object sprite instead of a UI sprite

Posted: Mon Jun 12, 2023 5:43 pm
by Tony Li
Glad to help!