Page 1 of 1
Showing different portraits for re-used conversations.
Posted: Wed Mar 09, 2022 4:37 pm
by jlhacode
I’m looking to use portraits for certain dialogue nodes, but I don’t want to couple the PNGs to the nodes themselves. The goal is to be able to re-use generic “thank you” and goodbye” conversations. I’d also like to be able to select the “mood” of the portrait as well.
For example, on a “Thank you” node, I’d like to be able to handle these hypothetical PNGs based on the actor.
Talk to NPC1:
- NPC1_portrait_happy.png
- NPC1_portrait_neutral.png
Talk to NPC4:
- NPC4_portrait_happy.png
- NPC4_portrait_neutral.png
Talk to ShopKeeper:
- ShopKeeper_portrait_happy.png
- ShopKeeper_portrait_neutral.png
What would be the best practice way of getting this done?
Re: Showing different portraits for re-used conversations.
Posted: Wed Mar 09, 2022 5:10 pm
by Tony Li
Hi,
You don't need to do anything special for that. This is a built-in feature of the Dialogue System.
Let's say you have 4 actors in your dialogue database: Player, NPC1, NPC4, and ShopKeeper.
Assign NPC1_portrait_happy and NPC1_portrait_neutral to NPC1 as portrait images 1 and 2.
Assign NPC4_portrait_happy and NPC4_portrait_neutral to NPC4 as portrait images 1 and 2.
Make a conversation between Player and ShopKeeper. In the ShopKeeper's dialogue text, use [pic=2] wherever you'd like to show portrait image 2 instead of portrait image 1. You can also use [var=Conversant] in your dialogue text to show the NPC's Display Name.
Create a GameObject for NPC1 if it doesn't already have one. Add a Dialogue Actor component, and select NPC1.
Create a GameObject for NPC4 if it doesn't already have one. Add a Dialogue Actor component, and select NPC4.
When you want NPC1 to play the ShopKeeper conversation, use a Dialogue System Trigger with NPC1 assigned to the Conversation Conversant field. The conversation will use NPC1's portraits.
When you want NPC4 to play the ShopKeeper conversation, use a Dialogue System Trigger with NPC4 assigned to the Conversation Conversant field. The same conversation will use NPC4's portraits.
More info on
Character GameObject Assignments.
Re: Showing different portraits for re-used conversations.
Posted: Wed Mar 09, 2022 7:01 pm
by jlhacode
Ahhhh, I didn't realize there was an actor field available in the inspector when selecting the actual DialogueDatabase asset! I have no idea why that didn't occur to me. Initially, I thought you were talking about the string fields in the 'Actors' tab in the Dialogue Editor.
The IDs in the DialogueDatabase seem to be the index that corresponds to the dictionary values in the Actors tab. Is it a good idea to rename the IDs to the name of their respective actors? I know that the name already exists in the Name field, but using the name as the ID would make it a bit easier to work with the dictionary.
Also, what's the difference between these fields?
- fields.png (93.61 KiB) Viewed 981 times
Re: Showing different portraits for re-used conversations.
Posted: Wed Mar 09, 2022 8:41 pm
by Tony Li
Hi,
The inspector may make more sense if you open the Dialogue Editor window. You can open the window by double-clicking a dialogue database asset, or selecting it and clicking 'Edit' in the inspector, or by clicking the Dialogue System banner on the Dialogue Manager GameObject if a dialogue database is assigned to the Dialogue Manager.
The Pictures field is unused. You can remove it from your template. It's a holdover for Chat Mapper compatibility.
When you have the Dialogue Editor window open, the inspector will show sections for Portrait Textures and Portrait Sprites. If your portrait images are sprites -- that is, you've imported them as Sprite (2D and UI) -- assign them to the Portrait Sprites section. If they're textures -- imported as Default or Editor/Legacy GUI -- assign them to Portrait Textures.
Re: Showing different portraits for re-used conversations.
Posted: Wed Mar 09, 2022 9:14 pm
by jlhacode
I have no idea how I didn't know this. I thought the Actor/Description tab was simply <string, string>, but it's so much more. This is going to be really useful. Thanks again Tony!
Re: Showing different portraits for re-used conversations.
Posted: Wed Mar 09, 2022 9:28 pm
by Tony Li
Happy to help!