Page 1 of 1

Dynamic Animated Portraits with Child Objects

Posted: Thu Jun 02, 2022 4:20 pm
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!

Re: Dynamic Animated Portraits with Child Objects

Posted: Thu Jun 02, 2022 5:02 pm
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.

Re: Dynamic Animated Portraits with Child Objects

Posted: Sat Jun 04, 2022 6:59 pm
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!

Re: Dynamic Animated Portraits with Child Objects

Posted: Sat Jun 04, 2022 8:25 pm
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
    }
}

Re: Dynamic Animated Portraits with Child Objects

Posted: Sat Oct 08, 2022 4:32 pm
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?

Re: Dynamic Animated Portraits with Child Objects

Posted: Sat Oct 08, 2022 8:25 pm
by Tony Li

Re: Dynamic Animated Portraits with Child Objects

Posted: Tue Oct 11, 2022 11:21 pm
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.

Re: Dynamic Animated Portraits with Child Objects

Posted: Wed Oct 12, 2022 8:24 am
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.