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!
How to set a custom avatar for each dialogue node?
Re: How to set a custom avatar for each dialogue node?
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:
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.
Re: How to set a custom avatar for each dialogue node?
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
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.
4. Attatched a listener for the event in the Awake
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
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);
}
}
3. Created a DialogueManager wrapper class in which is referenced the asset created at point 2.
Code: Select all
[SerializeField] private SpriteEvent m_rSpriteEvent;
Code: Select all
m_rSpriteEvent.EventRaised.AddListener(SetAvatar);
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 (11.76 KiB) Viewed 1052 times
Re: How to set a custom avatar for each dialogue node?
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.
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.
Re: How to set a custom avatar for each dialogue node?
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?
Re: How to set a custom avatar for each dialogue node?
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).
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).
Re: How to set a custom avatar for each dialogue node?
Ok, thanks a lot for your support!
Re: How to set a custom avatar for each dialogue node?
Glad to help!