How to set a custom avatar for each dialogue node?

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
yurijh
Posts: 13
Joined: Thu Oct 06, 2022 6:49 am

How to set a custom avatar for each dialogue node?

Post by yurijh »

I'd like to set a custom avatar for the actor talking in a particular node.
Using the Actors list options is not viable in my situation, the best solution to me would be to have a field in the inspector where put a sprite in while selecting a node.

What do you suggest to do to obtain this?

Thank you in advance!
User avatar
Tony Li
Posts: 21721
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to set a custom avatar for each dialogue node?

Post by Tony Li »

The Portrait Sprites list in the dialogue database's Actors section is generally the best way, but since it's not viable in your specific situation you can try this:

1. Put your portrait images in a folder named Resources.

2. Use the SetPortrait() sequencer command in the dialogue entry's Sequence field.

For example, say you've put a portrait image named Yuri_Happy in a folder named "Assets/Portraits/Yuri/Resources". To show this portrait in a dialogue entry spoken by Yuri, set the dialogue entry's Sequence to:

Code: Select all

SetPortrait(Yuri, Yuri_Happy);
{{default}}  // Also play the Dialogue Manager's Default Sequence.
yurijh
Posts: 13
Joined: Thu Oct 06, 2022 6:49 am

Re: How to set a custom avatar for each dialogue node?

Post by yurijh »

Thanks for your answer. The problem is that I need to give the designers a comfortable way to drag an image inside the inspector relative to that node.
By the way I think I've solved in this way.

1. Created a script named SpriteEvent

Code: Select all

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;

[CreateAssetMenu(fileName = "SpriteEvent", menuName = "Scriptables/SpriteEvent")]
public class SpriteEvent : ScriptableObject
{
    public UnityEvent<Sprite> EventRaised;

    public void Raise(Sprite rSprite) {
        EventRaised?.Invoke(rSprite);
    }
}
2. Created the SpriteEvent asset in the Project tab with Right click -> Scriptables -> SpriteEvent.

3. Created a DialogueManager wrapper class in which is referenced the asset created at point 2.

Code: Select all

[SerializeField] private SpriteEvent m_rSpriteEvent;
4. Attatched a listener for the event in the Awake

Code: Select all

m_rSpriteEvent.EventRaised.AddListener(SetAvatar);
5. Handled the avatar setting in the SetAvatar function.

Now I can put the SpriteEvent asset in the Events field of the dialogue node, then choose the Raise function selecting the sprite I want.

I hope I explained myself :)
Attachments
ha9YRIY.png
ha9YRIY.png (11.76 KiB) Viewed 930 times
User avatar
Tony Li
Posts: 21721
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to set a custom avatar for each dialogue node?

Post by Tony Li »

Hi,

That's fine. One thing to keep in mind, which may not be relevant to your project: OnExecute() UnityEvents are not exported if you export your dialogue database to an external text format such as Chat Mapper XML.

You can still export your dialogue database text to CSV using the Localization Export/Import feature. This will not affect OnExecute() events; they will be fine.
yurijh
Posts: 13
Joined: Thu Oct 06, 2022 6:49 am

Re: How to set a custom avatar for each dialogue node?

Post by yurijh »

Yes, I will probably need to Import/Export in the future, so if I use CSV I won't need to set the events again after import?
User avatar
Tony Li
Posts: 21721
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to set a custom avatar for each dialogue node?

Post by Tony Li »

If you export and import for localization using the Localization Export/Import feature, you will not need to set events again.

On the other hand, if you export your entire database using Export Database > CSV, this is not compatible with events. You will need to set events again.

So make sure to use Localization Export/Import if you must export to CSV (e.g., to add translations to other languages).
yurijh
Posts: 13
Joined: Thu Oct 06, 2022 6:49 am

Re: How to set a custom avatar for each dialogue node?

Post by yurijh »

Ok, thanks a lot for your support!
User avatar
Tony Li
Posts: 21721
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to set a custom avatar for each dialogue node?

Post by Tony Li »

Glad to help!
Post Reply