Dynamic Animated Portraits with Child Objects

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Scroogi
Posts: 7
Joined: Thu Dec 31, 2020 12:30 pm

Dynamic Animated Portraits with Child Objects

Post by Scroogi »

Hello Tony!

Thank you for the example project: "Animated Portraits Child Elements Example". It's almost exactly what I need!

Looking at this package, it seems like you replaced the portrait images with the multilayered portrait setup and animate it from there. My question is, is it possible to fill these fields dynamically so you can swap out the character in at runtime? (The sprites would be different, but the animations would all be the same)

Thanks for your help as always!
User avatar
Tony Li
Posts: 21033
Joined: Thu Jul 18, 2013 1:27 pm

Re: Dynamic Animated Portraits with Child Objects

Post by Tony Li »

Hi,

Yes; you'd just assign a different animator controller to each character's Dialogue Actor component. It's really no different from the basic animated portraits without child objects, except that the animations in each character's animator controller also animate the sprites of child objects, too.
Scroogi
Posts: 7
Joined: Thu Dec 31, 2020 12:30 pm

Re: Dynamic Animated Portraits with Child Objects

Post by Scroogi »

Hi Tony,

Thank you for your quick reply as always! I've messed with this for a few more days and still can't get it to work how I want it. I am setting the animation controller dynamically like you said, but I still can't figure out how to go about using it to customize my sprites appearance.

There is a character creator at the start, so the character will have some values like (hair 1, skin blue, clothes 4, eyes green) etc. I then want those changes to reflect in the animated portrait, but making the sprites set through an animation seems to require that I manually hook those sprites up beforehand. I can't figure out a way to pass the sprite info into an animator component in a way that works..

I could maybe make a separate script that sets the panel sprites individually when the conversation starts, but I am wondering if there's a better way you know of!
User avatar
Tony Li
Posts: 21033
Joined: Thu Jul 18, 2013 1:27 pm

Re: Dynamic Animated Portraits with Child Objects

Post by Tony Li »

Hi,

The character creator is the catch here. The example on the Dialogue System Extras page uses pre-made animation clips that assign specific sprites to the Image components. Each character's animator controller has a set of these pre-made animation clips.

In your scenario, on the other hand, you'll want to use different sprites for different body parts (hair, skin, eyes, etc.) based on the player's character creator choices, and you can't know the combination of those sprites beforehand because it's up to the player's character creator choices.

However, I think you can use animation layers in your animator controller to do this with minimal scripting. For example:
  • Layer 0 = Skin: Use an animator parameter to specify which skin animation to play (blue, red, green, etc.) on the portrait's body Image.
  • Layer 1 = Clothes: Use an animator parameter to specify which animation to play (dress, spacesuit, platemail, etc.) on the portrait's clothing Image.
  • Layer 2 = Hair: Use an animator parameter to specify which animation to play (buzzcut, ponytail, etc.) on the portraits hair Image, etc.
Then make a subclass of StandardUISubtitlePanel and override the SetAnimatorAtEndOfFrame method, such as:

Code: Select all

public class MySubtitlePanel : StandardUISubtitlePanel
{
    protected override IEnumerator SetAnimatorAtEndOfFrame(RuntimeAnimatorController animatorController)
    {
        yield return base.SetAnimatorAtEndOfFrame(animatorController);
        animator.SetInteger("Skin", 1); // blue skin
        animator.SetInteger("Clothes", 2); // spacesuit
        animator.SetInteger("Hair", 1); // buzzcut
    }
}
lcn_mc
Posts: 57
Joined: Wed Jun 29, 2022 1:56 pm

Re: Dynamic Animated Portraits with Child Objects

Post by lcn_mc »

Good day!

I've got time again to start working on my Unity project, and I've been trying (and failing, so far) to get animated portraits with child objects working. One initial question I have (and it applies to animated portraits in general), is whether there is any guidance around organizing game objects (for the dialogue actors) and their animations?

For example, I have a game object for a character in my game. That character's game object has to have a Dialogue Actor, so it can be picked up by the Dialogue Manager for conversations and such. I want this character to have an animated portrait that consists of three parts: A pose (the basic portrait itself, minus eyes and a mouth), eyes (that can blink), and a mouth (that opens/closes based on whether the character is speaking or not).

I tried fiddling with it a bit, and while I can get regular animated portraits working (thanks again to your help a few months back), I just can't get animated portraits with child objects going. I'm not even sure how to properly visualize them in the editor to make sure that, for example, the eyes and mouths are in the right place.

I would be really interested in seeing an example project here at some point where you have multiple characters with child objects setup that each have parts in a conversation, so I could poke at that and see where I'm going wrong. Anything like that planned, Tony?
lcn_mc
Posts: 57
Joined: Wed Jun 29, 2022 1:56 pm

Re: Dynamic Animated Portraits with Child Objects

Post by lcn_mc »

Tony,

Yep, that's the project I was looking at. In it, the animated portrait with child elements is applied directly to the portrait game object within the Dialogue Manager's tree. What I was asking about in my post is whether you have any plans to release another example project using animated portraits with child elements where they're applied to multiple characters, each of whom is its own game object.
User avatar
Tony Li
Posts: 21033
Joined: Thu Jul 18, 2013 1:27 pm

Re: Dynamic Animated Portraits with Child Objects

Post by Tony Li »

Nothing is planned. Some options that come to mind are using rendertextures (the Extras page has a rendertexture example) or using Spine (integration). Or, if you don't mind a little scripting, you can make a subclass of StandardUISubtitlePanel and override SetContent() to manage portraits however you want.
Post Reply